CMU
UM


Function polyadd:
adding two vectors of different lengths

Below is the function polyadd.m. This function will add two polynomials together even if they do not have the same length. To use polyadd.m in Matlab, enter polyadd(poly1,poly2). Copy the following text into a file polyadd.m, and put it in the same directory as the Matlab software, or in a directory which is contained in Matlab's search path. The function itself was written by Justin Shriver of the University of Michigan.


function[poly]=polyadd(poly1,poly2)
%Copyright 1996 Justin Shriver
%polyadd(poly1,poly2) adds two polynominals possibly of uneven length
if length(poly1)<length(poly2)
  short=poly1;
  long=poly2;
else
  short=poly2;
  long=poly1;
end
mz=length(long)-length(short);
if mz>0
  poly=[zeros(1,mz),short]+long;
else
  poly=long+short;
end

Use your browser's "Back" button to return to the previous page.

8/29/96 JDP