POLYADD
=POLYADD(a, b, [drop_leading_zeros]) =POLYSUB(a, b, [drop_leading_zeros])
Argument | Description | Example |
---|---|---|
a | A polynomial defined by coefficients in descending order of power | |
b | A polynomial defined by coefficients in descending order of power | |
drop_leading_zeros | (default=FALSE) If TRUE, drops leading zero terms | FALSE |
In the template file, navigate to the Polynomials worksheet to see the POLYADD function in action.
Description
Adding and subtracting polynomials is trivial when the vectors of coefficients are the same size. But, it requires a bit of logic to match up the correct terms when the polynomials are different degrees.
POLYADD(a,b) adds polynomial a and polynomial b, resulting in polynomial c which is a row vector the same length as the longest of the two original vectors. Leading zero terms are not removed from the polynomial, unless you use drop_leading_zeros=TRUE.
POLYSUB(a,b) subtracts polynomial b from polynomial a, and is based on POLYADD:
POLYSUB(a,b) = POLYADD(a,-b)
For these polynomial functions, the polynomial is defined as p(x) = βn*xn + βn-1*xn-1 + … + β2*x2 + β1*x1 + β0, and the coefficients should be defined as a row vector: {βn,βn-1,...,β1,β0}.
If the resulting polynomial c is a zero vector and you have set drop_leading_zeros to TRUE, the function will return a #N/A error.
Lambda Formula
This code for using POLYADD 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)
/** * Add two polynomials a + b = c */ POLYADD = LAMBDA(a,b,[drop_leading_zeros], LET(doc,"https://www.vertex42.com/lambda/polyadd.html", na,COLUMNS(a), nb,COLUMNS(b), c,IF(na=nb,a+b, IF(na>nb,a+HSTACK(SEQUENCE(1,na-nb,0,0),b), b+HSTACK(SEQUENCE(1,nb-na,0,0),a) )), IF(drop_leading_zeros=TRUE,DROP(c,0,MATCH(TRUE,c<>0,0)-1),c) )); /** * Subtract polynomial b from polynomial a: a - b = c */ POLYSUB = LAMBDA(a,b,[drop_leading_zeros], LET(doc,"https://www.vertex42.com/lambda/polyadd.html", POLYADD(a,-b,drop_leading_zeros) ));
Named Function for Google Sheets
Name: POLYADD Description: Add two polynomials: a + b = c Arguments: a, b Function: [in the works]
POLYADD Examples
Test: Copy and Paste this LET function into a cell =LET( a, {1,2,0,4,5}, b, {-3,0,3}, POLYADD(a,b) ) Result: {1,2,-3,4,8}
=LET( a, {1,2,4}, b, {1,0,1}, POLYSUB(a,b, TRUE) ) Result: {2,3}
=LET( a, {0,0,1,2,3}, POLYADD(a, 0*a, TRUE) ) Result: {1,2,3}
See Also
POLYVAL, POLYFIT, POLYMULT, POLYDIV