MATLAB - Polynomial Division



Polynomial division is the process of dividing one polynomial by another. In MATLAB, you can perform polynomial division using the deconv function, which computes the deconvolution of two polynomials. Since polynomial division is essentially the inverse operation of polynomial multiplication, the deconv function can be used for polynomial division.

Using deconv() Function in Matlab

The deconv() function in MATLAB helps you to divide one polynomial by another.

Syntax

[x,r] = deconv(y,h)

Imagine you have two polynomials, P(x) and Q(x).When you divide P(x) by Q(x), you get the result called the quotient X(x) and a remainder R(x). The deconv() function in matlab does this division for you.

For example , if you have P(x) = 6x3 + 5x2 + 4x + 3 and Q(x) = 2x + 1, using deconv() will give you the quotient X(x) = 3x2 + 2x + 1 and the remainder R(x) = 0.

In Matlab , you use deconv(y, h) where y is coefficients of P(x) and h are the coefficients of of Q(x). The function returns the coefficients of X(x) as quotient and R(x) as remainder.

Example 1: Division of Polynomials

Let us consider this two polynomials as shown below −

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

The coefficients for above polynomials is as follows −

P = [ 6  5  4  3 ];
Q = [2 1]

Here is a Matlab code,

% Define the coefficients of the polynomials
P = [6 5 4 3];  % Coefficients of P(x) = 6x^3 + 5x^2 + 4x + 3
Q = [2 1];      % Coefficients of Q(x) = 2x + 1

% Perform the polynomial division
[quotient, remainder] = deconv(P, Q);

% Display the results
disp('Quotient coefficients:');
disp(quotient);

disp('Remainder coefficients:');
disp(remainder);

In the example above − The result of dividing P(x) by Q(x), i.e., the polynomial resulting from the division. The leftover polynomial that can't be divided further by Q(x).

The quotient X(x) will be a polynomial of degree 2, as P(x) is of degree 3 and Q(x) is of degree 1.

The remainder R(x) will be a constant term, as it represents the leftover part after division.

When the code is executed the output we get is as follows −

>> % Define the coefficients of the polynomials
P = [6 5 4 3];  % Coefficients of P(x) = 6x^3 + 5x^2 + 4x + 3
Q = [2 1];      % Coefficients of Q(x) = 2x + 1

% Perform the polynomial division
[quotient, remainder] = deconv(P, Q);

% Display the results
disp('Quotient coefficients:');
disp(quotient);

disp('Remainder coefficients:');
disp(remainder);

Quotient coefficients:
    3.0000    1.0000    1.5000

Remainder coefficients:
         0         0         0    1.5000

>>

Example 2: Higher-Degree Polynomials

Let's divide two higher-degree polynomials.

Polynomials:

P(x) = 4x5 + 3x4 + 2x3 + x2 + 5x + 6

Q(x) = 2x2 + x + 1

Coefficients: 
P = [ 4 3 2 1 5 6 ]
Q = [ 2 1 1 ]

To solve above polynomial division the code we have is −

% Define the coefficients of the polynomials
P = [4 3 2 1 5 6];  % Coefficients of P(x) = 4x^5 + 3x^4 + 2x^3 + x^2 + 5x + 6
Q = [2 1 1];        % Coefficients of Q(x) = 2x^2 + x + 1

% Perform the polynomial division
[quotient, remainder] = deconv(P, Q);

% Display the results
disp('Quotient coefficients:');
disp(quotient);

disp('Remainder coefficients:');
disp(remainder);

In the code above we have −

  • P(x) is of degree 5.
  • Q(x) is of degree 2.
  • The quotient will be a polynomial of degree 3, and the remainder will be a polynomial of degree 1.

On code execution in matlab command window the output we get is −

>> % Define the coefficients of the polynomials
P = [4 3 2 1 5 6];  % Coefficients of P(x) = 4x^5 + 3x^4 + 2x^3 + x^2 + 5x + 6
Q = [2 1 1];        % Coefficients of Q(x) = 2x^2 + x + 1

% Perform the polynomial division
[quotient, remainder] = deconv(P, Q);

% Display the results
disp('Quotient coefficients:');
disp(quotient);

disp('Remainder coefficients:');
disp(remainder);

Quotient coefficients:
    2.0000    0.5000   -0.2500    0.3750

Remainder coefficients:
         0         0         0         0    4.8750    5.6250

>> 

Example 3: Division Resulting in Zero Remainder

Consider two polynomials where the division results in zero remainder.

Polynomials:
P(x) = x4 + 4x3 + 6x2 + 4x + 1  (which is the expansion of (x+1)4)
Q(x) = x + 1

Coefficients:
P = [ 1 4 6 4 1 ]

Q = [ 1 1 ]
  

The matlab code we have is −

% Define the coefficients of the polynomials
P = [1 4 6 4 1];  % Coefficients of P(x) = x^4 + 4x^3 + 6x^2 + 4x + 1
Q = [1 1];        % Coefficients of Q(x) = x + 1

% Perform the polynomial division
[quotient, remainder] = deconv(P, Q);

% Display the results
disp('Quotient coefficients:');
disp(quotient);

disp('Remainder coefficients:');
disp(remainder);

In the code above,

  • Since P(x) is exactly divisible by Q(x), the remainder will be zero.
  • The quotient will be the result of dividing P(x) by Q(x), i.e., (x+1)3

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

>> % Define the coefficients of the polynomials
P = [1 4 6 4 1];  % Coefficients of P(x) = x^4 + 4x^3 + 6x^2 + 4x + 1
Q = [1 1];        % Coefficients of Q(x) = x + 1

% Perform the polynomial division
[quotient, remainder] = deconv(P, Q);

% Display the results
disp('Quotient coefficients:');
disp(quotient);

disp('Remainder coefficients:');
disp(remainder);


Quotient coefficients:
     1     3     3     1

Remainder coefficients:
     0     0     0     0     0

>> 

Example 4: Division of a Polynomial by a Constant

If you divide a polynomial by a constant (degree 0 polynomial), the quotient will simply be the original polynomial divided by that constant.

Polynomials:
P(x) = 3x3 + 6x2 + 9x + 12
Q(x) = 3 (constant)

Coefficients:
P = [ 3 6 9 12 ]
Q = [ 3 ]

The matlab code we have is −

% Define the coefficients of the polynomials
P = [3 6 9 12];  % Coefficients of P(x) = 3x^3 + 6x^2 + 9x + 12
Q = [3];         % Coefficients of Q(x) = 3 (constant)

% Perform the polynomial division
[quotient, remainder] = deconv(P, Q);

% Display the results
disp('Quotient coefficients:');
disp(quotient);

disp('Remainder coefficients:');
disp(remainder);

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

>> % Define the coefficients of the polynomials
P = [3 6 9 12];  % Coefficients of P(x) = 3x^3 + 6x^2 + 9x + 12
Q = [3];         % Coefficients of Q(x) = 3 (constant)

% Perform the polynomial division
[quotient, remainder] = deconv(P, Q);

% Display the results
disp('Quotient coefficients:');
disp(quotient);

disp('Remainder coefficients:');
disp(remainder);

Quotient coefficients:
     1     2     3     4

Remainder coefficients:
     0     0     0     0

>> 
Advertisements