Evaluating symbolic expressions
In the context of scientific computing, there is often the need of first making symbolic manipulations and then converting the symbolic result into a floating-point number .
The central tool for evaluating a symbolic expression is evalf
. It converts symbolic expressions to floating-point numbers by using the following:
pi.evalf() # returns 3.14159265358979
The data type of the resulting object is Float
(note the capitalization), which is a SymPy data type that allows floating-point numbers with an arbitrary number of digits (arbitrary precision).
The default precision corresponds to 15 digits, but it can be changed by giving evalf
an extra positive integer argument specifying the desired precision in terms the numbers of digits,
pi.evalf(30) # returns 3.14159265358979323846264338328
A consequence of working with arbitrary precision is that numbers can be arbitrary small, that is, the limits of the classical floating-point representation...