Analyzing real-valued functions
SymPy contains a rich calculus toolbox to analyze real-valued functions: limits, power series, derivatives, integrals, Fourier transforms, and so on. In this recipe, we will show the very basics of these capabilities.
How to do it...
- Let's define a few symbols and a function (which is just an expression depending on
x
):>>> from sympy import * init_printing() >>> var('x z')
>>> f = 1 / (1 + x**2)
- Let's evaluate this function at
1
:>>> f.subs(x, 1)
- We can compute the derivative of this function:
>>> diff(f, x)
-
What is 's limit to infinity? (Note the double o (
oo
) for the infinity symbol):>>> limit(f, x, oo)
- Here's how to compute a Taylor series (here, around 0, of order 9). The Big O can be removed with the
removeO()
method.>>> series(f, x0=0, n=9)
- We can compute definite integrals (here, over the entire real line):
>>> integrate(f, (x, -oo, oo))
- SymPy can also compute...