Differentiate a polynomial with multidimensional coefficients in Python

To differentiate a polynomial with multidimensional coefficients, use the polynomial.polyder() method in NumPy. This function differentiates polynomial coefficients c along a specified axis, returning the derivative coefficients.

The coefficient array represents polynomials where [1,2,3] means 1 + 2*x + 3*x², while [[1,2],[1,2]] represents 1 + 1*x + 2*y + 2*x*y if axis=0 is x and axis=1 is y.

Syntax

numpy.polynomial.polynomial.polyder(c, m=1, scl=1, axis=0)

Parameters

The function accepts the following parameters ?

  • c − Array of polynomial coefficients (multidimensional arrays correspond to different variables)
  • m − Number of derivatives taken, must be non-negative (Default: 1)
  • scl − Scaling factor applied to each differentiation (Default: 1)
  • axis − Axis over which the derivative is taken (Default: 0)

Example

Let's differentiate a polynomial with multidimensional coefficients ?

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

# Create a multidimensional array of polynomial coefficients
c = np.arange(4).reshape(2,2)

# Display the coefficient array
print("Our coefficient Array...\n", c)

# Check the Dimensions
print("\nDimensions of our Array...\n", c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n", c.dtype)

# Get the Shape
print("\nShape of our Array object...\n", c.shape)

# Differentiate the polynomial using polyder()
print("\nResult...\n", P.polyder(c))
Our coefficient Array...
 [[0 1]
 [2 3]]

Dimensions of our Array...
 2

Datatype of our Array object...
 int64

Shape of our Array object...
 (2, 2)

Result...
 [[2. 3.]]

Differentiating Along Different Axes

You can specify different axes for differentiation ?

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

# Create coefficient array
c = np.array([[1, 2, 3], [4, 5, 6]])
print("Original coefficients:\n", c)

# Differentiate along axis 0 (default)
result_axis0 = P.polyder(c, axis=0)
print("\nDifferentiation along axis 0:\n", result_axis0)

# Differentiate along axis 1
result_axis1 = P.polyder(c, axis=1)
print("\nDifferentiation along axis 1:\n", result_axis1)
Original coefficients:
 [[1 2 3]
 [4 5 6]]

Differentiation along axis 0:
 [[4. 5. 6.]]

Differentiation along axis 1:
 [[2. 6.]
 [5. 12.]]

Using Multiple Derivatives and Scaling

You can take higher-order derivatives with scaling ?

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

# Coefficient array representing polynomial: 1 + 2x + 3x² + 4x³
c = np.array([1, 2, 3, 4])
print("Original coefficients:", c)

# First derivative
first_deriv = P.polyder(c, m=1)
print("First derivative:", first_deriv)

# Second derivative
second_deriv = P.polyder(c, m=2)
print("Second derivative:", second_deriv)

# Second derivative with scaling factor
scaled_deriv = P.polyder(c, m=2, scl=2)
print("Scaled second derivative:", scaled_deriv)
Original coefficients: [1 2 3 4]
First derivative: [2. 6. 12.]
Second derivative: [ 6. 24.]
Scaled second derivative: [24. 96.]

Conclusion

The polynomial.polyder() method efficiently differentiates polynomials with multidimensional coefficients. Use the axis parameter to control differentiation direction and m for higher-order derivatives. The scaling factor scl is useful for linear variable transformations.

Updated on: 2026-03-26T19:50:28+05:30

309 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements