Search⌘ K

Numerical Evaluation

Explore numerical evaluation in SymPy to convert symbolic expressions into numerical values. Learn about rational number representation, the evalf() method for float conversion, and substituting values into expressions to calculate results. This lesson helps you apply numerical techniques essential for scientific computations using symbolic math in Python.

Numeric types

While SymPy primarily focuses on symbols, it is impossible to have a completely symbolic system without the ability to numerically evaluate expressions. Many operations will directly use numerical evaluation, such as plotting a function or solving an equation numerically.

SymPy has 3 numeric types: rational, real, and integers. Since rational is the new one, let’s discuss it here:

Rational

The rational class represents a rational number as a pair of two integers: the numerator and the denominator.

Rational(1, 4) 

represents 14\frac{1}{4} ...