INTERP(3pm)

πŸ“¦
version 2.085 Β· 4 versions
, in ubuntu noble

πŸ’– INTERP(3pm) β€” bestie's guide to PDL::GSL::INTERP πŸ’–

okay so. you're here for the INTERP(3pm) page from the User Contributed Perl Documentation, and honestly? you came to the right place. sit down, grab a boba, we're talking about interpolation. ✨

🌸 NAME 🌸

PDL::GSL::INTERP β€” it's the PDL interface to the Interpolation routines chillin' inside GSL. that's it, that's the name, iconic behavior. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so basically this is an interface to the interpolation package that lives in the GNU Scientific Library. GSL said "here's some splines," PDL said "say less," and this module was born. no cap. 🫢


✨ SYNOPSIS ✨

here's the whole vibe, copy-paste ready, no notes:

use PDL;
use PDL::GSL::INTERP;

my $x = sequence(10);
my $y = exp($x);

my $spl = PDL::GSL::INTERP->init('cspline',$x,$y);

my $res = $spl->eval(4.35);
$res = $spl->deriv(4.35);
$res = $spl->deriv2(4.35);
$res = $spl->integ(2.1,7.4);

look at that. build a spline, evaluate it, take some derivatives, integrate it. main character energy fr fr. πŸ’…


πŸŽ€ NOMENCLATURE πŸŽ€

okay this part is important so listen up bestie. throughout this whole doc we try to use the same variables that show up in the original GSL documentation (peep the See Also if you wanna go straight to the source). and the thing is, GSL loves calling its variables "a" and "b".

but here's the tea: good Perl coding practices are like "girl, do NOT use $a and $b as your Perl variables," so we don't. instead:

  • Parameters "a" and "b" get called $pa and $pb respectively πŸ’–
  • Limits (of domain or of integration) get called $la and $lb πŸ’–

and yeah, this little artifact is just sitting here in the text, so here you go, verbatim, no gatekeeping:

#line 64 "INTERP.pm"

periodt. moving on.


πŸ”₯ FUNCTIONS πŸ”₯

πŸ’œ init πŸ’œ

Signature: (double x(n); double y(n); gsl_spline *spl)

the init method spins up a brand new instance of INTERP. it needs, as its input, an interpolation type plus two ndarrays holding the x and y values you wanna interpolate. 🌈

now, the GSL routines are picky β€” they require that x be monotonically increasing β€” so a quicksort gets performed by default to make sure of it. and if you already know your data's good? you can skip that quicksort by passing the option {Sort => 0}. slay. ✨

the available interpolation types are, drumroll please πŸ₯:

  • linear
  • polynomial
  • cspline (natural cubic spline)
  • cspline_periodic (periodic cubic spline)
  • akima (natural akima spline)
  • akima_periodic (periodic akima spline)

please check the GSL documentation for more info on those β€” that's the assignment, bestie, iykyk. πŸ’…

Usage:

$blessed_ref = PDL::GSL::INTERP->init($interp_method,$x,$y,$opt);

Example:

$x = sequence(10);
$y = exp($x);

$spl = PDL::GSL::INTERP->init('cspline',$x,$y)
$spl = PDL::GSL::INTERP->init('cspline',$x,$y,{Sort => 1}) #same as above

# no sorting done on x, user is certain that x is monotonically increasing
$spl = PDL::GSL::INTERP->init('cspline',$x,$y,{Sort => 0});
⚠️ heads up: init does not process bad values. it will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. so like, know that about it. 😭

🧚 eval 🧚

Signature: (double x(); double [o] out(); gsl_spline *spl;gsl_interp_accel *acc)

the eval function returns the interpolating function at a given point. and listen β€” it will barf with an "input domain error" if you try to extrapolate. do not test it. it's not a vibe. πŸ’€

Usage:

$result = $spl->eval($points);

Example:

my $res = $spl->eval($x)

good news though: eval processes bad values. it will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. we love a function that handles its business. 🫢


🌸 deriv 🌸

Signature: (double x(); double [o] out(); gsl_spline *spl;gsl_interp_accel *acc)

the deriv function returns the derivative of the interpolating function at a given point. same energy as before: it will barf with an "input domain error" if you try to extrapolate. 🚫

Usage:

$result = $spl->deriv($points);

Example:

my $res = $spl->deriv($x)
⚠️ deriv does not process bad values. it will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. πŸ’€

πŸ“ deriv2 πŸ“

Signature: (double x(); double [o] out(); gsl_spline *spl;gsl_interp_accel *acc)

the deriv2 function returns the second derivative of the interpolating function at a given point. yes, second. it's giving overachiever. and yeah β€” it will barf with an "input domain error" if you try to extrapolate. ✨

Usage:

$result = $spl->deriv2($points);

Example:

my $res = $spl->deriv2($x)
⚠️ deriv2 does not process bad values. it will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. 😭

πŸ‘‘ integ πŸ‘‘

Signature: (double a(); double b(); double [o] out(); gsl_spline *spl;gsl_interp_accel *acc)

the integ function returns the integral of the interpolating function between two points. and you already know what's coming: it will barf with an "input domain error" if you try to extrapolate. the extrapolation jumpscare is real in every single one of these. πŸ’€

Usage:

$result = $spl->integ($la,$lb);

Example:

my $res = $spl->integ($la,$lb)
⚠️ integ does not process bad values. it will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. 🫢

πŸ™ˆ BUGS πŸ™ˆ

Feedback is welcome. (that's literally it. they're so chill about it. come talk to us. πŸŽ€)


🌈 SEE ALSO 🌈


πŸ’– AUTHOR πŸ’–

This file copyright (C) 2003 Andres Jordan <andresj@physics.rutgers.edu>. All rights reserved. There is no warranty. You are allowed to redistribute this software/documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file. πŸ“œ

The GSL interpolation module was written by Gerard Jungman. ✨


and that's the whole page bestie!! perl v5.38.2, dated 2024-04-10 β€” thanks for reading my TED talk, now go interpolate something gorgeous. mwah. πŸ’‹πŸ’…πŸ¦‹

πŸ“¦ where this page comes from