SUPPORT / SAMPLES & SAS NOTES
 

Support

Sample 25001: Compute approximate first and second derivatives for (x,y) data

DetailsCodeResultsAboutRate It

Compute approximate first and second derivatives for (x,y) data

Contents: Purpose / Requirements / Usage / Details
PURPOSE:
This sample program illustrates how to use PROC EXPAND to compute approximate first and second derivatives for paired (x,y) data. More specifically, this sample program does the following:
  • Generates data (X,Y) according to a high degree polynomial.
  • Plots Y vs X.
  • Uses PROC EXPAND to fit a cubic spline to this data. See Conversion Methods: The Spline Method in the EXPAND chapter of the SAS/ETS User's Guide.
  • Outputs the derivatives of the spline at each of the x values. These values are stored in the variable DERIV1.
  • Graphs Y and DERIV1 vs X.
  • Uses PROC EXPAND to fit a cubic spline to the values of DERIV1.
  • Outputs the derivatives of the spline at each X value. These values are stored in the variable called DERIV2.
  • Graphs Y, DERIV1 and DERIV2 vs. X.
REQUIREMENTS:
SAS/ETS Software, Version 6 or later.
USAGE:
Note that these splines work well when there are many (x,y) values so that the curve is fairly well-defined. You can vary the BY 0.01 value in the first DATA step to see how well (or how poorly) this method works when there are more (or fewer) x values in the input data set for this curve.
DETAILS:
The approximate first derivatives are obtained by computing the exact first derivative of a cubic smoothing spline which is fit to the (x,y) data.

Under certain conditions, as in this example, a cubic spline as fit by PROC EXPAND offers a good approximation of the underlying function. In this case, the exact derivative values computed from the spline are close approximations to the actual derivative values of the underlying function.

Likewise, it's true that if the spline poorly approximates the underlying function, then the exact derivatives of the spline will poorly approximate the actual function derivatives. So the quality of the derivative approximation depends on how closely the cubic smoothing spline approximates the underlying function.




These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.