Numerical Differentiation of a Spline Curve
/****************************************************************/
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: GPLOTSM */
/* TITLE: Numerical Differentiation of a Spline Curve */
/* PRODUCT: IML */
/* SYSTEM: ALL */
/* KEYS: MATRIX GRAPHICS */
/* PROCS: IML GPLOT */
/* DATA: */
/* */
/* SUPPORT: LWB UPDATE: 20FEB89 */
/* REF: */
/* MISC: THIS JOB SHOWS HOW TO OBTAIN THE POINTS THAT */
/* PROC GPLOT USES FOR THE I=SMXX INTERPOLATION ON */
/* THE SYMBOL STATEMENT USING THE CALL SPLINE */
/* FUNCTION IN PROC IML. NOTE THAT THE XX VALUE MUST */
/* BE SPECIFIED IN THE IML PROGRAM. */
/* */
/* */
/****************************************************************/
DATA ONE;
INPUT X Y;
CARDS;
1 4
2 9
3 20
4 25
5 1
6 5
7 -4
8 12
;
PROC IML;
USE ONE;
READ ALL INTO MAT;
/* CALCULATE THE SMOOTHING PARAMETER */
SMVAL=45; /* SUPPLY THE XX VALUE FROM THE SYMBOL STATEMENT HERE */
Z=MAT[,1];
S=(Z-Z[+]/NROW(Z))[##];
SM=S##1.5 / (10##(9-(SMVAL*.1)));
/* FIT THE SPLINE AND GET 200 INTERPOLATED POINTS */
CALL SPLINEC(FITTED,C,ENDVAL,MAT,SM,,200);
/* DIFFERENTIATE THE CURVE */
D=C[,1]||(C[,3:NCOL(C)]#( (1:(NCOL(C)-2))@J(NROW(C),1,1) ) );
D=D||J(NROW(D),1,0);
DFIT=SPLINEV(D,,200);
FITTED=FITTED||DFIT[,2];
CREATE TWO VAR {NEWX NEWY DY};
APPEND FROM FITTED;
/* MERGE DATA SETS FOR A COMPARATIVE PLOT */
DATA THREE;
MERGE ONE TWO;
TITLE "SM45 AND SPLINE FROM IML OVERLAID";
PROC GPLOT;
PLOT Y*X NEWY*NEWX/OVERLAY;
SYMBOL1 I=SM45 C=BLUE V=NONE;
SYMBOL2 I=JOIN C=RED V=NONE;
RUN;
TITLE "SPLINE CURVE AND DIFFERENTIATED CURVE";
PROC GPLOT;
PLOT NEWY*NEWX DY*NEWX/OVERLAY;
SYMBOL1 I=JOIN C=BLUE V=NONE;
SYMBOL2 I=JOIN C=RED V=NONE;
RUN;
title;