Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning SciPy for Numerical and Scientific Computing Second Edition

You're reading from   Learning SciPy for Numerical and Scientific Computing Second Edition Quick solutions to complex numerical problems in physics, applied mathematics, and science with SciPy

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher Packt
ISBN-13 9781783987702
Length 188 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Toc

Univariate polynomials

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime