SymPy – evalf() function


SymPy – evalf() function



”;


This function evaluates a given numerical expression upto a given floating point precision upto 100 digits. The function also takes subs parameter a dictionary object of numerical values for symbols. Consider following expression


>>> from sympy.abc import r 
>>> expr=pi*r**2 
>>> expr

The above code snippet gives an output equivalent to the below expression −

$Pi{r^2}$

To evaluate above expression using evalf() function by substituting r with 5


>>> expr.evalf(subs={r:5})

The above code snippet gives the following output −

78.5398163397448

By default, floating point precision is upto 15 digits which can be overridden by any number upto 100. Following expression is evaluated upto 20 digits of precision.


>>> expr=a/b 
>>> expr.evalf(20, subs={a:100, b:3})

The above code snippet gives the following output −

33.333333333333333333

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *