MATLAB - Derivatives of Polynomials



In mathematics, a derivative represents the rate of change of a function with respect to a variable. In simple terms, it tells us how a function is changing at any given point. Derivatives are fundamental in calculus and are widely used in fields like physics, engineering, and economics to model change and motion.

For example, if you have a function that describes the position of a car over time, the derivative of that function would give you the car's velocity (rate of change of position).

Derivatives of Polynomials

A polynomial is a mathematical expression consisting of variables raised to different powers, combined with coefficients. For example, the polynomial P(x) = 3x2 + 2x + 5 is a second degree polynomial.

The derivative of a polynomial function is found by applying a simple rule: For each term, multiply the coefficient by the exponent, and then reduce the exponent by 1. This process is repeated for each term in the polynomial.

For example, consider the polynomial:

P(x) = 3x3 + 4x2 + 2x + 1

The derivative , P(x), is calculated as −

  • For the term 3x3: Multiply 3 by 3 (the exponent), resulting in 9x2.
  • For the term 4x2: Multiply 4 by 2, resulting in 8x.
  • For the term 2x: Multiply 2 by 1, resulting in 2.
  • The constant term (1) has a derivative of 0.

So, the derivative is −

P(x) = 9x2 + 8x + 2

Derivatives in MATLAB

MATLAB makes it easy to compute derivatives of polynomials using built-in functions. A polynomial in MATLAB is represented by a vector containing its coefficients, ordered by descending powers of the variable.

To find the derivative of a polynomial, MATLAB provides the polyder function.

Syntax

k = polyder(p)
k = polyder(a,b)
[q,d] = polyder(a,b)

Syntax Explanation

k = polyder(p) calculates the derivative of a polynomial given by the coefficients in p, resulting in a new polynomial k(x) that represents the derivative d/dx p(x).

k = polyder(a,b) computes the derivative of the product of two polynomials a and b, resulting in a new polynomial k(x) that represents.

$$\mathrm{\frac{d}{dx}[a(x) \: \cdot \: b(x)]}$$

[q, d] = polyder(a, b) computes the derivative of the quotient of two polynomials a and b, returning two polynomials: q(x) (the numerator) and d(x) (the denominator), representing the derivative of a(x)/b(x).

Example 1: Calculating derivative using polyder(p)

Consider we have a polynomial

P(x) = 4x3 + 3x2 + 2x + 1

This polynomial can be represented by the vector of its coefficients in MATLAB −

p = [4 3 2 1];

To compute the derivative of this polynomial, we use the polyder function in MATLAB −

k = polyder(p);

On execution of the code in matlab command window the output is.

>> p = [4 3 2 1];
k = polyder(p)

k =

    12     6     2

>>

For the term 4x3, the derivative is 12x2 (multiply the coefficient 4 by the exponent 3 and reduce the exponent by 1).

For the term 3x2, the derivative is 6x.

For the term 2x, the derivative is 2.

For the constant term 1 has a derivative of 0.

Thus, the derivative polynomial is :

k(x) = 12x2 + 6x + 2

In Matlab the result of k wil be : [12 6 2]

Example 2: Another example to find derivatives of a polynomial

Consider following polynomial

p(x) = 5x4 + 2x3 + 7x2 - 3x + 8  

This polynomial can be represented by the vector of its coefficients in MATLAB −

p = [5 -2 7 -3 8]

To find the derivative of this polynomial will make use of the polyder function in matlab.

k = polyder(p)

This command will return the coefficients of the derivative of polynomial p.

When you execute the code in matlab command window the output is :

>> p = [5 -2 7 -3 8];
k = polyder(p)

k =

    20    -6    14    -3

>> 

The vector k = [20 -6 14 -3] represents the polynomial

k(x) = 20x3 - 6x2 + 14x - 3

Example 3: Derivative of the Product of Two Polynomials Using polyder(a, b)

Let's consider two polynomials

a(x) = 2x2 + 3x  + 1
b(x) = 4x + 5

These polynomials can be represented by vectors of their coefficients in MATLAB:

a = [2 3 1]
b = [4 5]  

To compute the derivative of the product of these two polynomials, we use the polyder function with two input arguments.

k = polyder(a, b);

This will return the coefficients of the derivative of the product of a(x) and b(x).

When you execute the code in matlab command window the output we get is :

>> a = [2 3 1];
b = [4 5];  
k = polyder(a, b)

k =

    24    44    19

>>

So, the derivative polynomial is: k(x) = 24x2 + 44x + 19

Example 4: Derivative of two given polynomials

Consider two different polynomials.

a(x) = 3x3 + 2x2 + x + 4
b(x) = x2 - 5x + 6

These polynomials can be represented by the following coefficient vectors in MATLAB.

a = [3 2 1 4];
b = [1 -5 6];

To compute the derivative of the product of these two polynomials, we use the polyder function with the vectors a and b as inputs

k = polyder(a, b);

This command will return the coefficients of the derivative of the product of a(x) and b(x).

When the code is executed in matlab command window the output is :

>> a = [3 2 1 4];
b = [1 -5 6];
k = polyder(a, b)

k =

    15   -52    27    22   -14

>> 

So, the derivative polynomial is −

k(x) = 15x4 - 52x3 + 27x2 + 22x - 14

Example 5: Derivative of the Quotient of Two Polynomials Using [q, d] = polyder(a, b)

Let's consider two polynomials −

a(x) = 4x2 + 3x + 2
b(x) = x2 - 2x + 1

These polynomials can be represented by vectors of their coefficients in Matlab.

a = [4 3 2];
b = [1 -2 1];

To compute the derivative of the quotient a(x) / b(x), we use the polyder function with two output arguments q and d.

[q,d] = polyder(a,b)

This will return two polynomials: q(x) (the numerator) and d(x) (the denominator) of the derivative of a(x) / b(x).

When the code is executed in matlab command window the output is :

>> a = [4 3 2];
b = [1 -2 1];
[q,d] = polyder(a,b)

q =

   -11     4     7


d =

     1    -4     6    -4     1

>> 
Advertisements