PPINT
=PPINT(pp_array, [a], [b])
Argument | Description | Example |
---|---|---|
pp_array | A piecewise polynomial (pp) data structure array | [see below] |
a | (default=x1) The lower limit for the integration | 2 |
b | (default=xN) The upper limit for the integration | 8 |
cumulative | (default=FALSE) If TRUE, returns the cumulative integral corresponding to each segment | FALSE |
In the template file, navigate to the Polynomials worksheet to see the PPINT function in action.
Description
The definite integral of a polynomial, \(P(x) = \int_a^bp(x)dx\), can be calculated exactly using POLYINT. Likewise, a Piecewise Polynomial, which is made up of separate polynomial segments, can be integrated exactly, using POLYINT on individual segments.
A piecewise polynomial is defined only within the bounds [x1,xN] where the first column of the data structure array is the column vector of N break points. For the purposes of integration, values outside that domain are considered to be zero.
The following example is a piecewise polynomial data structure described within the PPVAL function documentation.
Integrating this example from a=-10 to b=100 is the same as integrating it from 0 to 15, since all values outside of [0,15] are treated as zero.
=LET( pp_array, {0,0,2,-1,1,10;4,0,0,-5,0,126;10,-1,5,1,4,-54;15,0,0,0,0,0}, PPINT(pp_array) ) Result: 528.5833
Cumulative Integration
If the optional cumulative parameter is TRUE, the function returns the cumulative integral corresponding to each segment where P(x1)=0 and P(xk) is:
$$ P(x_{k\ne1}) = \sum_{i=2}^{k} \int_a^bp_{i-1}(x)dx\ $$If a and b are not specified, then the cumulative integral of the piecewise polynomial from a=x1 to b=xN is:
$$ P(x_{k\ne1}) = \sum_{i=2}^{k} \int_{x_{i-1}}^{x_i}p(x)dx\ $$For the example above:
=LET( pp_array, {0,0,2,-1,1,10;4,0,0,-5,0,126;10,-1,5,1,4,-54;15,0,0,0,0,0}, PPINT(pp_array,,,TRUE) ) Result: {0; 154.667; 550.667; 528.5833}
Lambda Formula
This code for using PPINT 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)
/** * Definite Integral of a Piecewise Polynomial from a to b */ PPINT = LAMBDA(pp_array,[a],[b],[cumulative], LET(doc,"https://www.vertex42.com/lambda/ppint.html", breaks,INDEX(pp_array,0,1), pieces,ROWS(breaks)-1, coeffs,DROP(pp_array,-1,1), a,IF(OR(ISBLANK(a),a<INDEX(breaks,1)),INDEX(breaks,1),a), b,IF(OR(ISBLANK(b),b>INDEX(breaks,pieces+1)),INDEX(breaks,pieces+1),b), areas,SCAN(0,SEQUENCE(pieces+1),LAMBDA(acc,i, IF(i=1,0,LET( x_1,INDEX(breaks,i-1), x_2,INDEX(breaks,i), IF(NOT(AND(a<INDEX(breaks,i),b>INDEX(breaks,i-1))),acc+0, acc+POLYINT(CHOOSEROWS(coeffs,i-1),,MAX(0,a-x_1),MIN(b,x_2)-x_1) ) )))), IF(cumulative=TRUE,areas,INDEX(areas,pieces+1,1)) ));
Named Function for Google Sheets
Name: PPINT Description: Integrate a Piecewise Polynomial Arguments: pp_array, a, b, cumulative Function: [in the works]
PPINT Examples
=LET( xs, LINSPACE(0,6*PI(),31), ys, xs/4*SIN(xs)+4, spline, CSPLINE(xs,ys), PPINT(spline) ) Result: 70.706534 Error: 0.0207The default cubic spline function calculates slopes using only forward, backward, and central difference approximations. But, we can improve the accuracy using PDIFF to obtain higher-order estimates of the slopes.
=LET( xs, LINSPACE(0,6*PI(),31), ys, xs/4*SIN(xs)+4, slopes, PDIFF(xs,ys,1,3), spline, CSPLINE(xs,ys,,slopes), PPINT(spline) ) Result: 70.678297 Error: -0.0075Note: The trapezoidal rule using TRAPZ for these same 31 points results in 70.8419 with an error of 0.156.
See Also
TRAPZ, PPVAL, CSPLINE, LINSPACE, PDIFF, POLYINT