- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Differentiate a polynomial in Python

To differentiate a polynomial, use the polynomial.polyder() method in Python Numpy. Return the polynomial coefficients c differentiated m times along axis. At each iteration the result is multiplied by scl (the scaling factor is for use in a linear change of variable). The argument c is an array of coefficients from low to high degree along each axis, e.g., [1,2,3] represents the polynomial 1 + 2*x + 3*x**2 while [[1,2],[1,2]] represents 1 + 1*x + 2*y + 2*x*y if axis=0 is x and axis=1 is y.

The method returns the Polynomial coefficients of the derivative. The 1st parameter, c is an array of polynomial coefficients. If c is multidimensional the different axis correspond to different variables with the degree in each axis given by the corresponding index. The 2nd parameter, m are number of derivatives taken, must be non-negative. (Default: 1)

The 3rd parameter is scl. Each differentiation is multiplied by scl. The end result is multiplication by scl**m. This is for use in a linear change of variable. (Default: 1). The 4th parameter is axis. It's the axis over which the derivative is taken. (Default: 0). The result is (d/dx)(c) = 2 + 6x + 12x**2

## Steps

At first, import the required library −

import numpy as np from numpy.polynomial import polynomial as P

Create an array of polynomial coefficients i.e. 1 + 2x + 3x**2 + 4x**3 −

c = np.array([1,2,3,4])

Display the coefficient array −

print("Our coefficient Array...

",c)

Check the Dimensions −

print("

Dimensions of our Array...

",c.ndim)

Get the Datatype −

print("

Datatype of our Array object...

",c.dtype)

Get the Shape −

print("

Shape of our Array object...

",c.shape)

To differentiate a polynomial, use the polynomial.polyder() method in Python Numpy −

print("

Result...

",P.polyder(c))

## Example

import numpy as np from numpy.polynomial import polynomial as P # Create an array of polynomial coefficients i.e. # 1 + 2x + 3x**2 + 4x**3 c = np.array([1,2,3,4]) # Display the coefficient array print("Our coefficient Array...

",c) # Check the Dimensions print("

Dimensions of our Array...

",c.ndim) # Get the Datatype print("

Datatype of our Array object...

",c.dtype) # Get the Shape print("

Shape of our Array object...

",c.shape) # To differentiate a polynomial, use the polynomial.polyder() method in Python Numpy. # Return the polynomial coefficients c differentiated m times along axis. At each iteration the result is multiplied by scl (the scaling factor is for use in a linear change of variable). The argument c is an array of coefficients from low to high degree along each axis, e.g., [1,2,3] represents the polynomial 1 + 2*x + 3*x**2 while [[1,2],[1,2]] represents 1 + 1*x + 2*y + 2*x*y if axis=0 is x and axis=1 is y. print("

Result...

",P.polyder(c))

## Output

Our coefficient Array... [1 2 3 4] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (4,) Result... [ 2. 6. 12.]

- Related Questions & Answers
- Differentiate a polynomial with multidimensional coefficients in Python
- Differentiate a polynomial and set the derivatives in Python
- Differentiate a polynomial with multidimensional coefficients over axis 1 in Python
- Differentiate a polynomial with multidimensional coefficients over specific axis in Python
- Differentiate a polynomial and multiply each differentiation by a scalar in Python
- Differentiate a polynomial, set the derivatives and multiply each differentiation by a scalar in Python
- Integrate a polynomial in Python
- Differentiate a Hermite_e series in Python
- Differentiate a Hermite series in Python
- Differentiate a Laguerre series in Python
- Differentiate a Legendre series in Python
- Differentiate a Chebyshev series in Python
- Raise a polynomial to a power in Python
- Convert a Chebyshev series to a polynomial in Python
- Convert a polynomial to a Chebyshev series in Python