Find derivative of polynomial in Python

In this article, we are gonna learn how to find the derivative of a polynomial in Python. To do this task we are going to use NumPy. 

  • NumPy is a library for the Python programming language which is used for scientific computing and to perform various operations on arrays.
  • So NumPy has numpy.polyder(p,m) which returns the derivative of the specified order of a polynomial where:

p = polynomial whose derivative we have to find.

m = order of differentiation.

It is an easy task by using numpy in Python. So, let’s get started.

Also read: numpy.polyder() in Python with Examples

  1. First, we will construct the polynomial whose derivative we have to find which we are gonna do by using class numpy.poly1d:

SYNTAXnumpy.poly1d([the polynomial’s coefficients in decreasing powers])

       2. Then, we will find the derivative by numpy.polyder().

Let’s understand this through examples :

# importing libraries 
import numpy as np 
 
# Constructing polynomial  
d1 = np.poly1d([2,2,3])  
d2 = np.poly1d([1, 3, 4, 2])  
    
print ("d1 : ", d1)  
print ("\n d2 : \n", d2)

Now, this is the first step in which we are constructing the polynomial.

m = np.polyder(d1, 1) 
n = np.polyder(d2, 3) 
print ("\n\nUsing polyder") 
print ("d1 derivative of order = 1 : \n", m)  
print ("d2 derivative of order = 3 : \n", n)

So, this is the second step in which we are finding derivatives of our polynomials.

Here, is the derivative of polynomial d1 and its first-order derivative while n is the derivative of polynomial d2 and its third-order derivative.

Screenshot:

Find derivative of polynomial in Python

 

Therefore here it is, a simple and easy tutorial to find the derivative of a polynomial in just two steps in Python.

Leave a Reply

Your email address will not be published. Required fields are marked *