≡ ▼
Work in Progress :: Please contact us to report errors, typos, etc.
=L_PPDER(pp_array)
ArgumentDescriptionExample
pp_arrayA piecewise polynomial (pp) data structure array[see below]

Download the Template

In the template file, navigate to the Polynomials worksheet to see the L_PPDER function in action.

Description

L_PPDER returns the derivative of a piecewise polynomial as another piecewise polynomial. Each derivative of a polynomial reduces the degree by one, so the pp_array returned by L_PPDER(pp_array) will have one less column of coefficients.

The derivative of a polynomial can be calculated using the L_POLYDER function, so finding the derivative of an entire piecewise polynomial is simply a matter of finding the derivative of each individual segment and assembling a new piecewise polynomial structure.

pp_array structure: A piecewise polynomial is defined within the bounds [x1,xN] where the first column of the data structure array is the column vector of N break points. The other columns are the coefficients for each polynomial segment. The following example is a piecewise polynomial data structure described within the L_PPVAL function documentation.

Data Structure for a Piecewise Polynomial in Excel

L_PPDER Example

The following example graphs the first derivative of the piecewise polynomial shown above. Note that in this case the first derivative is not continuous.

=LET(
    pp_array, HSTACK({0;4;10;15},{0,2,-1,1,10; 0,0,-5,0,126; -1,5,1,4,-54}),
    xs, L_LINSPACE(0,15,100),
    dydx, L_PPVAL(L_PPDER(pp_array),xs)
)
Result: (see graph below)
PPDER Example - First Derivative Not Continuous

See the example below showing the use of L_PPDER with cubic splines.

Lambda Formula

This code for using L_PPDER 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)

/**
* Returns the derivative of a Piecewise Polynomial as another piecewise polynomial
*/
L_PPDER = LAMBDA(pp_array,
LET(doc,"https://www.vertex42.com/lambda/ppder.html",
    breaks,INDEX(pp_array,0,1),
    pieces,ROWS(breaks)-1,
    coeffs,DROP(pp_array,-1,1),
    newcoeffs,REDUCE(0,SEQUENCE(pieces),LAMBDA(acc,i,LET(
        deriv,L_POLYDER(CHOOSEROWS(coeffs,i)),
        IF(i=1,deriv,VSTACK(acc,deriv))
    ))),
    MAP(HSTACK(breaks,newcoeffs),LAMBDA(cell,IFERROR(cell,"")))
));

Named Function for Google Sheets

Name: L_PPDER
Description: Returns the Derivative of a Piecewise Polynomial
Arguments: pp_array
Function:
[in the works]

L_PPDER Examples

Example: First and Second Derivative of a Cubic Spline

The L_CSPLINE function creates a cubic spline that has a continuous first derivative. Consider the following example from the L_CSPLINE documentation:

CSPLINE Control Points and Piecewise Polynomial ArrayExample control points and resulting cubic piecewise polynomial array
Cubic Spline Example (compared to 'smoothed line' option)Comparison of CSPLINE with the "Smoothed Line" option in Excel

Using L_LINSPACE, L_PPDER and L_PPVAL like above, we can graph the first and second derivatives of this example cubic spline. We can see that it is indeed C1 continuous (first derivative is continuous), but it is not C2 continuous (second derivative is not continuous).

PPDER Example of a Cubic Spline - First Derivative and Second Derivative
Example: First and Second Derivative of a Natural Cubic Spline

A Natural Cubic Spline is defined to be C2 continuous. The following example is a natural cubic spline fit to the same points as the example above. Note that the second derivative is continuous in this case, and is zero at the end points.

=LET(
    x_cpts, {2;3;4;5;6;7;8;9;10;11;12},
    y_cpts, {4;4;2;3;1;1.5;5;2;2;4.5;4},
    pp_spline, L_NSPLINE(x_cpts,y_cpts),
    x_interp, L_LINSPACE(2,12,101),
    y_interp, L_PPVAL(pp_spline,x_interp),
    dy_interp, L_PPVAL( L_PPDER(pp_spline),x_interp),
    d2y_interp, L_PPVAL( L_PPDER(L_PPDER(pp_spline)),x_interp),
    HSTACK(x_interp,y_interp,dy_interp,d2y_interp)
)

Result: (see graph below)
Natural Cubic Spline Example - Showing First and Second Derivative

See Also

PPVAL, CSPLINE, PPINT, POLYDER

References & Resources
Disclaimer: This article is meant for educational purposes only. See the License regarding the LAMBDA code, and the site Terms of Use for the documentation.