1Spline(3) User Contributed Perl Documentation Spline(3)
2
3
4
6 require Math::Spline;
7 $spline=new Math::Spline(\@x,\@y)
8 $y_interp=$spline->evaluate($x);
9
10 use Math::Spline qw(spline linsearch binsearch);
11 use Math::Derivative qw(Derivative2);
12 @y2=Derivative2(\@x,\@y);
13 $index=binsearch(\@x,$x);
14 $index=linsearch(\@x,$x,$index);
15 $y_interp=spline(\@x,\@y,\@y2,$index,$x);
16
18 This package provides cubic spline interpolation of numeric data. The
19 data is passed as references to two arrays containing the x and y ordi‐
20 nates. It may be used as an exporter of the numerical functions or,
21 more easily as a class module.
22
23 The Math::Spline class constructor new takes references to the arrays
24 of x and y ordinates of the data. An interpolation is performed using
25 the evaluate method, which, when given an x ordinate returns the inter‐
26 polate y ordinate at that value.
27
28 The spline function takes as arguments references to the x and y ordi‐
29 nate array, a reference to the 2nd derivatives (calculated using Deriv‐
30 ative2, the low index of the interval in which to interpolate and the x
31 ordinate in that interval. Returned is the interpolated y ordinate. Two
32 functions are provided to look up the appropriate index in the array of
33 x data. For random calls binsearch can be used - give a reference to
34 the x ordinates and the x loopup value it returns the low index of the
35 interval in the data in which the value lies. Where the lookups are
36 strictly in ascending sequence (e.g. if interpolating to produce a
37 higher resolution data set to draw a curve) the linsearch function may
38 more efficiently be used. It performs like binsearch, but requires a
39 third argument being the previous index value, which is incremented if
40 necessary.
41
43 requires Math::Derivative module
44
46 require Math::Spline;
47 my @x=(1,3,8,10);
48 my @y=(1,2,3,4);
49 $spline=new Math::Spline(\@x,\@y);
50 print $spline->evaluate(5)."\n";
51
52 produces the output
53
54 2.44
55
57 $Log: Spline.pm,v $ Revision 1.1 1995/12/26 17:28:17 willijar Initial
58 revision
59
61 Bug reports or constructive comments are welcome.
62
64 John A.R. Williams <J.A.R.Williams@aston.ac.uk>
65
67 "Numerical Recipies: The Art of Scientific Computing" W.H. Press, B.P.
68 Flannery, S.A. Teukolsky, W.T. Vetterling. Cambridge University Press.
69 ISBN 0 521 30811 9.
70
71
72
73perl v5.8.8 1995-12-26 Spline(3)