Main Content

polydiv

Polynomial long division

Since R2024a

Description

[q,r] = polydiv(b,a) divides the polynomial represented by coefficient vector b by the polynomial represented by coefficient vector a. The results are the quotient polynomial represented by coefficient vector q and the remainder polynomial represented by coefficient vector r such that b = conv(a,q) + r.

example

Examples

collapse all

Create two vectors, b and a, containing the coefficients of the polynomials 2x3+7x2+4x+9 and x2+1, respectively. Divide the first polynomial by the second polynomial. The results are in quotient coefficients corresponding to the polynomial 2x+7 and remainder coefficients corresponding to 2x+2.

b = [2 7 4 9];
a = [1 0 1];
[q,r] = polydiv(b,a)
q = 1×2

     2     7

r = 1×4

     0     0     2     2

To check the division, you can reconstruct the original dividend polynomial from the divisor, quotient and remainder using conv.

bOrig = conv(a,q) + r
bOrig = 1×4

     2     7     4     9

Input Arguments

collapse all

Dividend polynomial coefficients, specified as a row or column vector.

Data Types: double | single
Complex Number Support: Yes

Divisor polynomial coefficients, specified as a row or column vector.

The vectors b and a can have different lengths or data types.

  • If one or both of b and a are of type single, then the outputs are also of type single. Otherwise, the outputs are of type double.

  • The lengths of the inputs typically satisfy length(a) <= length(b). However, if length(a) > length(b), then polydiv returns the outputs as q = 0 and r = b. With k = min(length(a),length(b)), these two cases are equivalent to b = conv(a(1:k),q) + r.

Data Types: double | single
Complex Number Support: Yes

Output Arguments

collapse all

Quotient polynomial coefficients, returned as a row or column vector such that b = conv(a,q) + r.

Data Types: double | single

Remainder polynomial coefficients, returned as a row or column vector such that b = conv(a,q) + r.

Data Types: double | single

Tips

  • [q,r] = polydiv(b,a) is equivalent to deconvolving vector a out of vector b using the polynomial long division method. However, using polynomial long division to find deconvolutions can result in numerically unstable results. For more numerically stable computations in finding the deconvolutions, use the least-squares method instead, as provided in the deconv function.

Version History

Introduced in R2024a

See Also

| | |