-
Book Overview & Buying
-
Table Of Contents
Learning SciPy for Numerical and Scientific Computing Second Edition - Second Edition
Polynomials are defined in SciPy as a NumPy class, poly1d. This class has a handful of methods associated to compute the coefficients of the polynomial (coeffs or simply c), to compute the roots of the polynomial (r), to compute its derivative (deriv), to compute the symbolic integral (integ), and to obtain the degree (order or simply o), as well as a method (variable) that provides a string holding the name of the variable we would like to use in the proper definition of the polynomial (see the example involving P2).
In order to define a polynomial, we must indicate either its coefficients or its roots:
>>> import numpy >>> P1=numpy.poly1d([1,0,1]) # using coefficients >>> print (P1)
The output is as follows:
2 1 x + 1
Now let's find roots, order, and derivative of P1:
>>> print (P1.r); print (P1.o); print (P1.deriv())
The output is as follows:
[ 0.+1.j 0.-1.j] 2 2 x
Let's use the poly1d class:
>>> P2...
Change the font size
Change margin width
Change background colour