# 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?

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;
```

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 Systems, Inc. Worldwide Headquarters

Aptech Systems, Inc.
2350 East Germann Road, Suite #21
Chandler, AZ 85286

Phone: 360.886.7100
FAX: 360.886.8922

• ### Training & Events

Want more guidance while learning about the full functionality of GAUSS and its capabilities? Get in touch for in-person training or browse additional references below.

• ### Tutorials

Step-by-step, informative lessons for those who want to dive into GAUSS and achieve their goals, fast.

• ### Want to find out more?

Get a real answer from a real person

• ### Have a Specific Question?

Get a real answer from a real person

• Need Support?
• ### Support Plans

Premier Support and Platinum Premier Support are annually renewable membership programs that provide you with important benefits including technical support, product maintenance, and substantial cost-saving features for your GAUSS System or the GAUSS Engine.

• ### User Forums

Join our community to see why our users are considered some of the most active and helpful in the industry!