MATLAB - Polynomial Division
MATLAB - Modern Polynomial Division
Section titled “MATLAB - Modern Polynomial Division”Polynomial division is a core algebraic operation used to simplify fractions of polynomials, find roots, and analyze transfer functions in control systems. In MATLAB, the primary function for numerical polynomial division is deconv, which stands for deconvolution—the inverse operation of polynomial multiplication (conv).
Using the deconv Function
Section titled “Using the deconv Function”The deconv function divides a numerator polynomial by a denominator polynomial, returning the quotient and the remainder.
Syntax
Section titled “Syntax”[quotient, remainder] = deconv(numerator_poly, denominator_poly)Where numerator_poly and denominator_poly are row vectors of coefficients in descending order of power. The output quotient and remainder are also coefficient vectors.
Example 1: Basic Division
Section titled “Example 1: Basic Division”Let’s divide P(x) = 6x³ + 5x² + 4x + 3 by Q(x) = 2x + 1.
%% Define the coefficient vectors for the numerator and denominatorP = [6 5 4 3]; % Represents 6x³ + 5x² + 4x + 3Q = [2 1]; % Represents 2x + 1
%% Perform the polynomial division[quotient, remainder] = deconv(P, Q);
%% Display the resultsdisp('Quotient coefficients:');disp(quotient); % Expected: [3 1 1.5]
disp('Remainder coefficients:');disp(remainder); % Expected: [0 0 0 1.5]
fprintf('Result: (%sx^2 + %sx + %s) with a remainder of %s\n', ... num2str(quotient(1)), num2str(quotient(2)), num2str(quotient(3)), ... num2str(remainder(end)));% The remainder vector is padded with leading zeros to match the length of P.Verification and Numerical Precision
Section titled “Verification and Numerical Precision”You can verify the result of the division using the fundamental relationship: Numerator = Quotient * Denominator + Remainder. In MATLAB, this is done using the conv and + operators.
Pro Tip: When working with floating-point numbers, the remainder might not be exactly zero due to precision limits. It’s good practice to check if it’s smaller than a small tolerance (e.g., 1e-12).
Example 2: Exact Division and Verification
Section titled “Example 2: Exact Division and Verification”Let’s divide P(x) = x⁴ + 4x³ + 6x² + 4x + 1 (which is (x+1)⁴) by Q(x) = x + 1. The result should be (x+1)³ with a zero remainder.
%% Define polynomials for exact divisionP = [1 4 6 4 1]; % (x+1)^4Q = [1 1]; % (x+1)
[quotient, remainder] = deconv(P, Q);
disp('Quotient (x+1)^3 coefficients:');disp(quotient); % Expected: [1 3 3 1]
disp('Remainder coefficients:');disp(remainder); % Expected: [0 0 0 0 0]
%% Verification Step% Reconstruct the original polynomial Preconstructed_P = conv(quotient, Q) + remainder;
% Check if the reconstruction is close to the originalis_verified = all(abs(P - reconstructed_P) < 1e-12);
if is_verified disp('Verification successful: P = conv(Q, Quotient) + Remainder');else disp('Verification failed.');endModern Approach: Symbolic Math Toolbox
Section titled “Modern Approach: Symbolic Math Toolbox”For analytical work, where precision is paramount and you want to work with expressions rather than just coefficients, the Symbolic Math Toolbox is the superior choice. It performs exact rational arithmetic.
% This requires the Symbolic Math Toolboxtry %% Define symbolic variable and polynomials syms x; sym_P = x^4 + 3*x^2 + 1; % Numerator sym_Q = x^2 + x + 1; % Denominator
%% The `quorem` function performs symbolic division [sym_quotient, sym_remainder] = quorem(sym_P, sym_Q, x);
%% Display the symbolic results fprintf('Symbolic Quotient: %s\n', string(sym_quotient)); fprintf('Symbolic Remainder: %s\n', string(sym_remainder));catch ME if strcmp(ME.identifier, 'MATLAB:UndefinedFunction') disp('Symbolic Math Toolbox is not installed. Skipping this example.'); else rethrow(ME); endendPractical Application: System Analysis
Section titled “Practical Application: System Analysis”In control theory, a transfer function is a ratio of two polynomials, G(s) = N(s) / D(s). If N(s) has a higher degree than D(s) (an improper transfer function), deconv can be used to separate it into a proper transfer function and a feed-forward term, which is crucial for analysis and simulation.