File Exchange

## Polynomial division by convolution - quotient and reminder

version 1.34 (1.58 KB) by

Division of two polynomials to get quotient and reminder using convolution matrix.

Updated

Polynomial division by convolution matrix approach.

Given b(x) and a(x), and find q(x) and r(x) in
b(x) = a(x)*q(x) + r(x)
where
b(x) = b(0)+ ... +b(k)*x^k + ... +b(n)*x^n
a(x) = a(0)+ ... +a(k)*x^k + ... +a(m)*x^m
q(x) = q(0)+ ...+ q(k)*x^k + ... +q(n-m)*x^(n-m)
r(x) = r(0)+ ...+ r(k)*x^k + ... +r(m-1)*x^(m-1)

If coefficients of b(x) and a(x) are all integers, then the entire process may involve mostly integer arithmetric operations. The roundoff errors may thus be eliminated.

This code is similar to the MATLAB's built-in function: 'deconv.m'.

Zeeshan Shareef

Thank you...
It help me alot.

Feng Cheng Chang

### Feng Cheng Chang (view profile)

Please try it again. It should have worked perfectly for both polynomials b(x) and a(x) with trailing zeros.
For the example you gave: b(x)=x^4+1 and a(x)=x^2, yielding the desired results: q(x)=x^2 and r(x)=1.
>> b = [1 0 0 0 1]; a = [1 0 0];
>> [q,r,qc,rc,c] = PolyDiv(b,a)
q = 1 0 0
r = 1
qc = 1 0 0
rc = 0 1
c = 1
Also it should be OK for b(x) with leading zero coefficients; however, not for a(x) with trailing zero coefficients.
>> b = [0 0 1 0 0 0 1 0]; a = [1 0 1 0 0];
>> [q,r,qc,rc,c] = PolyDiv(b,a)
q = 1 0
r = -1 0 1 0
qc = 0 0 1 0
rc = -1 0 1 0
c = 1
Anyway I thank you for giving me this peculiar case to work with.
I will update the code involving any polynomials with both leading and trailing zero coefficients.
Feng Cheng Chang

### Krishna Prasad (view profile)

This programme is not working when the coefficient of the polynomial are zeros.
e.g a(x)=x^4+1
b(x)=x^2