Spline(3pm)

πŸ“¦
version 0.02 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 like binsearch, 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