Polynomial division - derived form covolution

by

 

10 Oct 2011 (Updated )

Polynomial division is derived directly from convolution.

poly_div(b,a)
function [q,r] = poly_div(b,a)
%
% *** Polynomial division -- revised.
%     Given b(x) and a(x),  find q(x) and r(x)  in 
%           b(x) = a(x)*q(x) + r(x).
%     Similar to MATLAB built-in  [q,r] = deconv(b,a).
%     F C Chang    Updated  12/12/12
 
      n = length(b)-1;   m = length(a)-1;
      a = [a,zeros(1,n-m)];  q = 0;
 for  k = 1:n+1,
   if k < n-m+2,
      q(k) = (b(k)-[q(1:k-1)]*[a(k:-1:2)].') /a(1);
   else,
      r(k-(n-m+1)) = b(k)-[q(1:n-m+1)]*[a(k:-1:k-n+m)].';
   end;
 end; 
 

Contact us