Spline(3pm)
π Spline β Math::Spline π
okay bestie, so this is Math::Spline, a User Contributed Perl Documentation page, and it's giving cubic spline interpolation of data. it's from Spline(3pm), and no cap, it's lowkey iconic for what it does. π
β¨ NAME β¨
Math::Spline β Cubic Spline Interpolation of data π¦
β¨ SYNOPSIS β¨
here's the whole vibe, fr fr:
use Math::Spline;
$spline = Math::Spline->new(\@x,\@y)
$y_interp=$spline->evaluate($x);
use Math::Spline qw(spline linsearch binsearch);
use Math::Derivative qw(Derivative2);
@y2=Derivative2(\@x,\@y);
$index=binsearch(\@x,$x);
$index=linsearch(\@x,$x,$index);
$y_interp=spline(\@x,\@y,\@y2,$index,$x);
β¨ DESCRIPTION β¨
so this package does cubic spline interpolation of numeric data, periodt. the data comes in as references to two arrays β one holding the x ordinates and one holding the y ordinates. you can use it as an exporter of the numerical functions, or, way more easily, as a class module. pick your fighter. π
the Math::Spline class constructor new takes references to the arrays of x and y ordinates of the data. then you do an interpolation with the evaluate method, which β when you hand it an x ordinate β gives you back the interpolated y ordinate at that value. slay. β¨
the spline function takes as arguments:
- references to the x and y ordinate array
- a reference to the 2nd derivatives (calculated using
Derivative2) - the low index of the interval in which to interpolate
- the x ordinate in that interval
and what does it return? the interpolated y ordinate, obviously. π
there are also two functions to look up the appropriate index in the array of x data:
binsearchβ for random calls, use this one. give it a reference to the x ordinates and the x lookup value, and it returns the low index of the interval in the data where that value lies.linsearchβ where the lookups are strictly in ascending sequence (like when you're interpolating to produce a higher resolution data set to draw a curve), this one may be used more efficiently. it performs likebinsearch, but it needs a third argument: the previous index value, which gets incremented if necessary.
πΈ NOTE πΈ
requires Math::Derivative module π«Ά
β¨ EXAMPLE β¨
require Math::Spline;
my @x=(1,3,8,10);
my @y=(1,2,3,4);
$spline = Math::Spline->new(\@x,\@y);
print $spline->evaluate(5)."\n";
produces the output
2.44
ate and left no crumbs, honestly. π₯
π¦ HISTORY π¦
$Log: Spline.pm,v $ Revision 1.1 1995/12/26 17:28:17 willijar Initial revision
the initial revision, bestie. 1995. vintage. π
π BUGS π
bug reports or constructive comments are welcome. (yes please, be nice about it π)
π AUTHOR π
John A.R. Williams <J.A.R.Williams@aston.ac.uk>
π SEE ALSO π
"Numerical Recipies: The Art of Scientific Computing" W.H. Press, B.P. Flannery, S.A. Teukolsky, W.T. Vetterling. Cambridge University Press. ISBN 0 521 30811 9.
okay that's the whole page, you're basically a spline girlie now. this was written for perl v5.36.0, dated 2022-11-19, and it's the Spline(3pm) page. go interpolate something cute. π
β¨ππ¦πΈ
π¦ where this page comes from
- debian bookworm: libmath-spline-perl 0.02-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmath-spline-perl 0.02-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmath-spline-perl 0.02-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmath-spline-perl 0.02-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmath-spline-perl 0.02-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms