NumPy also provides methods to work with polynomials, and includes a package called numpy.polynomial
to create, manipulate, and fit the polynomials. A common application of this would be interpolation and extrapolation. In this section, our focus is still on using ndarray
with NumPy functions instead of using polynomial instances. (Don't worry, we will still show you the usage of the polynomial class.)
As we stated in the matrix class section, using ndarray
with NumPy functions is preferred since ndarray
can be accepted in any functions while matrix and polynomial objects need to be converted, especially when communicating to other programs. Both of them provided handy properties, but in most cases ndarray
would be good enough.
In this section, we will cover how to calculate the coefficients based on a set of roots, and how to solve a polynomial equation, and finally we will evaluate integrals and derivatives. Let's start by calculating the coefficients of a polynomial...