POLYDIV
=POLYDIV(a, b)
Argument | Description | Example |
---|---|---|
a | The dividend: A polynomial defined by coefficients in descending order of power | |
b | The divisor: A polynomial defined by coefficients in descending order of power |
In the template file, navigate to the Polynomials worksheet to see the POLYDIV function in action.
Description
Long division of two polynomials \(a(x) / b(x)\) when \(b(x)\ne0\) results in a polynomial \(q(x)\) and a remainder polynomial \(r(x)\) such that \(a(x)=b(x)q(x)+r(x)\). The POLYDIV function returns polynomial q(x) stacked vertically on top of polynomial r(x).
The algorithm used in the POLYDIV function is based on polynomial long division, which you can read about on wikipedia.
Example:
$$4x^5 + 8x^4 + 7x^3 + 5x + 8 \over 2x^2 + 3x + 4$$ $$a(x) = 4x^5 + 8x^4 + 7x^3 + 5x + 8$$ $$b(x) = 2x^2 + 3x + 4$$=LET( a, {4,8,7,0,5,8}, b, {2,3,4}, POLYDIV(a,b) ) Result: {2, 1, -2, 1; 0, 0, 10, 4}
The first row of the result is the quotient q(x) and the second row is the remainder r(x):
$$q(x) = 2x^3 + 1x^2 - 2x + 1$$ $$r(x) = 10x + 4$$To check the results, we can evaluate a=bq+r as follows:
=LET( b, {2,3,4}, q, {2,1,-2,1}, r, {10,4}, POLYADD(POLYMULT(b,q),r) ) Result: {4,8,7,0,5,8}
Lambda Formula
This code for using POLYDIV in Excel is provided under the License as part of the LAMBDA Library, but to use just this function, you may copy the following code directly into your spreadsheet.
Code for AFE Workbook Module (Excel Labs Add-in)
/** * Divide two polynomials using long division: a/b = q remainder r * Returns polynomial q stacked vertically on top of polynomial r */ POLYDIV = LAMBDA(a,b, LET(doc,"https://www.vertex42.com/lambda/polydiv.html", na,COLUMNS(a), nb,COLUMNS(b), result,IF(na<nb,VSTACK(0*b,b), REDUCE(VSTACK(0*a,a),SEQUENCE(na-nb+1,1,na-nb,-1),LAMBDA(acc,i,LET( dividend,CHOOSEROWS(acc,2), t,INDEX(dividend,1,na-nb-i+1)/INDEX(b,1,1), tv,IF(i>0,HSTACK(t,SEQUENCE(1,i,0,0)),t), q,IF(i>0,HSTACK(t*b,SEQUENCE(1,i,0,0)),t*b), r,POLYADD(dividend,-q), VSTACK(POLYADD(INDEX(acc,1,0),tv),r) )))), IF(na>=nb,DROP(result,0,nb-1),result) ));
Named Function for Google Sheets
Name: POLYDIV Description: Divide polynomial a by polynomial b resulting in polynomial q and remainder r Arguments: a, b Function: [in the works]
POLYDIV Examples
Step 1: Divide p(x) by (x+1) =LET( a, {1,3,-11,-3,10}, b, {1,1}, POLYDIV(a,b) ) Result: {1, 2,-13, 10; 0, 0, 0, 0} Step 2: Divide q(x) by (x-1) =LET( a, {1,2,-13,10}, b, {1,-1}, POLYDIV(a,b) ) Result: {1, 3, -10; 0, 0, 0}
After factoring out the two known roots, we have \(q(x)=x^2+3x-10\). Using QUADRATIC, we can find the two remaining roots:
=QUADRATIC({1,3,-10})
Result: {2; -5}
See Also
POLYVAL, POLYFIT, POLYMULT, POLYADD