December 2017
Intermediate to advanced
386 pages
10h 42m
English
In [6]: p = np.poly1d([1,0,0,0,0,0]); \ ...: print (p) 51 xIn [7]: np.polyder(p,1)(1.0)In [7]: p.deriv()(1.0)Out[7]: 5.0 Out[7]: 5.0 In [8]: np.polyder(p,2)(1.0)In [8]: p.deriv(2)(1.0)Out[8]: 20.0Out[8]: 20.0
Symbolic differentiation is another way to achieve exact results:
In [9]: from sympy import diff, symbolsIn [10]: x = symbols('x', real=True)In [11]: diff(x**5, x)In [12]: diff(x**5, x, x)Out[11]: 5*x**4Out[12]: 20*x**3In [13]: diff(x**5, x).subs(x, 1.0) Out[13]: 5.00000000000000In [14]: diff(x**5, x, x).subs(x, 1.0)Out[14]: 20.0000000000000
Note the slight improvement (both in notation and simplicity of coding) when we differentiate more involved functions than simple polynomials. For example, for g(x) = e-xsinx at ...
Read now
Unlock full access