Resources

GAUSS code for polynomial division?

0

I am looking for some GAUSS code to perform polynomial division. Does anyone have a procedure or a link?

Tags: asked March 13, 2013
aptech
352

1 Answer

0
accepted

Here is a procedure:

proc(2) = polyDiv(c1,c2);
	
   local m1, m2, m3, r, d, c0;
   m1 = rows(c1);
   m2 = rows(c2);
	
   if m2 > m1;
	retp(error(0));
   elseif m2 == m1;	
      c0 = c1[1] / c2[1];
      r = {};
      for i(2,m1,1);
         r = r | (c1[i] - c0 * c2[i]);
      endfor;
      retp(c0,r);
   else;
      c0 = {};
      m3 = m1 - m2 + 1;
      for j(1,m3,1);
         c0 = c0 | (c1[1] / c2[1]);
         c1 = c1[2:rows(c1),.];
         for i(2,m2,1);
            c1[i-1] = c1[i-1] - c0[rows(c0)] * c2[i];
         endfor;
      endfor;
      r = c1;
      retp(c0,r);
   endif;
endp;

Here is a simple example using the procedure:

c1 = { 1, -12, 0, -42 };  //x^3 - 12x^2 -42
c2 = { 1, -3 };           //x - 3

{ c3, r } = polyDiv(c1,c2);

c1 = polymult(c2,c3);
c1[rows(c1)]  = c1[rows(c1)] + r;

print c1;
aptech
352