Dew MtxVec NET
Spline1D Routines
Summary
Cubic spline interpolation.

Unit
Polynoms

Declaration
Procedure Spline1D(Y: TVec; PiecePoly: TPiecePoly; Knots: boolean = false);

Description
Interpolates cubic splines between consecutive Y points. The assumption is that Y is evaluated at [0,1,2,...] i.e. X values are [0,1,2,...]. If the Knot parameter is true then the first and the last Y value will be used for the end conditions.
 See Also 
Interpolate 
Linear1D 
PolyFit 
TPiecePoly 

Example 1

uses MtxExpr, Math387, MtxVec, MtxVecEdit, MtxVecTee,Polynoms; procedure TForm1.Button1Click(Sender: TObject); var X,Y,Y2: Vector; PP : TPiecePoly; i : Integer; YVal : TSample; begin PP := TPiecePoly.Create; try // generate function - note that X values are monotonical X := Ramp(100,0,1); Y := RandUniform(100,0,50) + Ramp(100,100,0.25); // construct cubic splines, but do not evaluate them Spline1D(X,Y,PP); X := Ramp(800,0,0.125); //get interpolation points PP.Evaluate(X,Y2); // evaluate DrawIt(Y,'Original'); DrawIt(Y2,'Interpolated'); finally PP.Destroy; end; end;
#include "MtxVecCPP.h" //MtxVecCPP.cpp must be included in the project #include "Polynoms.hpp" #include "MtxVecTee.hpp" #include "MtxVecEdit.hpp" void __fastcall TForm1::BitBtn1Click(TObject *Sender) { Vector X,Y,Y2; TPiecePoly *PP; int i; double YVal; PP = new TPiecePoly(); try { // generate function - note that X values are monotonical X->Size(100); Y->Size(100); Y2->Size(100); X->Ramp(0,1); Y->RandUniform(0,50); Y2->Ramp(100,0.25); Y += Y2; // construct cubic splines, but do not evaluate them Spline1D(X,Y,PP); X->Size(800); X->Ramp(0,0.125); //get interpolation points PP->Evaluate(X,Y2); // evaluate DrawIt(Y,"Original",false); DrawIt(Y2,"Interpolated",false); } __finally { delete PP; } }
using Dew.Math; using Dew.Math.Units; using Dew.Math.Tee; namespace Dew.Examples { private void Example() { Vector X = new Vector(0); Vector Y = new Vector(0); Vector Y2 = new Vector(0); TPiecePoly PP = new TPiecePoly(); int i; double YVal; // generate function - note that X values are monotonical X.Size(100); Y.Size(100); Y2.Size(100); X.Ramp(0,1); Y.RandUniform(0,50); Y2.Ramp(100,0.25); Y += Y2; // construct cubic splines, but do not evaluate them Polynoms.Spline1D(X,Y,PP); X.Size(800); X.Ramp(0,0.125); //get interpolation points PP.Evaluate(X,Y2); // evaluate TeeChart.DrawIt(Y,"Original",false); TeeChart.DrawIt(Y2,"Interpolated",false); } }


Declaration
Procedure Spline1D(X, Y: TVec; PiecePoly: TPiecePoly);

Description
The procedure interpolates cubic splines between consequtive (X,Y) pairs. Spline1D does not return interpolated points. It constructs piece-wise polynomial, which in term can be used for evaluating (by using the TPiecePoly.Evaluate method) cubic splines. To directly obtain interpolated values, use the Interpolate routine.

If X.Length=Y.Length, then the "not-a-knot" end conditions are used. If Y.Length = X.Length +2 then the "knot" end conditions are used. X values must be monotonic or the result will not be valid.

Copyright 2008 Dew Research
http://www.dewresearch.com