How to compute derivative using Numpy?
In this article, we will learn how to compute derivatives using NumPy. Generally, NumPy does not provide any robust function to compute the derivatives of different polynomials. However, NumPy can compute the special cases of one-dimensional polynomials using the functions numpy.poly1d() and deriv().
- poly1d(): It helps to define a polynomial expression or a function.
- deriv(): Calculates and gives us the derivative expression
- At first, we need to define a polynomial function using the numpy.poly1d() function.
- Then we need to derive the derivative expression using the derive() function.
- At last, we can give the required value to x to calculate the derivative numerically.
Below are some examples where we compute the derivative of some expressions using NumPy. Here we are taking the expression in variable ‘var’ and differentiating it with respect to ‘x’.
To calculate double derivative we can simply use the deriv() function twice.