INTERP(3pm)
π 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$paand$pbrespectively π - Limits (of domain or of integration) get called
$laand$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 π₯:
linearpolynomialcspline(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 π
PDL- The GSL documentation for interpolation is online at
<https://www.gnu.org/software/gsl/doc/html/interp.html>
π 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
- ubuntu noble: pdl 1:2.085-1ubuntu1 Β· 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