Math::...:Interp(3pm)

πŸ’– NAME πŸ’–

Math::GSL::Interp β€” it's giving interpolation. Fr fr, that's the whole vibe.

It's part of the User Contributed Perl Documentation situation, and yes bestie, it's the Math::...:Interp(3pm) page you were looking for. πŸŽ€


✨ SYNOPSIS ✨

use Math::GSL::Interp qw/:all/;
my $x_array = [ 0.0, 1.0, 2.0, 3.0, 4.0 ];

# check that we get the last interval if x == last value
$index_result = gsl_interp_bsearch($x_array, 4.0, 0, 4);
print "The last interval is $index_result \n";

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so. buckle up. every function in this module, one by one, no skips, we're not doing that today. πŸ’…

  • gsl_interp_accel_alloc() β€” hands you back a pointer to an accelerator object. think of it as a lil iterator just for interpolation lookups πŸ‘‘ it keeps track of the state of your lookups so all the fancy acceleration strategies can actually do their thing.
  • gsl_interp_accel_find($a, $x_array, $x_size, $x) β€” does an actual lookup on the data array $x_array (which has size $size, the third arg), using the accelerator $a you're passing in. this is literally how lookups happen while an interpolation is being evaluated. it returns an index i where:
$x_array[i] <= $x < $x_array[i+1]
  • gsl_interp_accel_reset β€” it's here, it's listed, it exists. 🫢
  • gsl_interp_accel_free($a) β€” frees the accelerator object $a. bye bestie, you served well πŸ’œ
  • gsl_interp_alloc($T, $alloc) β€” returns a brand-new, freshly allocated interpolation object of type $T for $size data-points. $T has to be one of the constants down below, no improvising. πŸŽ€
  • gsl_interp_init($interp, $xa, $ya, $size) β€” initializes the interpolation object interp for the data (xa,ya), where xa and ya are arrays of size size. important lore: the interpolation object (gsl_interp) does not save the data arrays xa and ya. it only stores the static state it computed from the data. and the xa data array is always assumed to be strictly ordered with increasing x values β€” the behavior for any other arrangement is not defined, so don't test it, I'm begging 😭
  • gsl_interp_name($interp) β€” returns the name of the interpolation type that $interp is using. intro please ✨
  • gsl_interp_min_size($interp) β€” returns the minimum number of points the interpolation type of $interp needs. for example, Akima spline interpolation requires a minimum of 5 points. iconic requirement honestly.
  • gsl_interp_eval_e($interp, $xa, $ya, $x, $acc) β€” returns the interpolated value of y for a given point $x, using the interpolation object $interp, the data arrays $xa and $ya, and the accelerator $acc. it returns 0 if the operation succeeded, 1 otherwise β€” and also the y value. two-for-one fr.
  • gsl_interp_eval($interp, $xa, $ya, $x, $acc) β€” returns the interpolated value of y for a given point $x, using the interpolation object $interp, the data arrays $xa and $ya, and the accelerator $acc. that's it, that's the whole job, and it ate. πŸ’…
  • gsl_interp_eval_deriv_e($interp, $xa, $ya, $x, $acc) β€” computes the derivative value of y for a given point $x, using $interp, the data arrays $xa and $ya, and the accelerator $acc. returns 0 if it succeeded, 1 otherwise, plus the d value. πŸ“
  • gsl_interp_eval_deriv($interp, $xa, $ya, $x, $acc) β€” returns the derivative d of an interpolated function at a given point $x, using the interpolation object interp, the data arrays $xa and $ya, and the accelerator $acc.
  • gsl_interp_eval_deriv2_e($interp, $xa, $ya, $x, $acc) β€” computes the second derivative d2 of an interpolated function at a given point $x, using $interp, the data arrays $xa and $ya, and the accelerator $acc. returns 0 if it succeeded, 1 otherwise, plus the d2 value. ✨
  • gsl_interp_eval_deriv2($interp, $xa, $ya, $x, $acc) β€” returns the second derivative d2 of an interpolated function at a given point $x, using the interpolation object $interp, the data arrays $xa and $ya, and the accelerator $acc.
  • gsl_interp_eval_integ_e($interp, $xa, $ya, $a, $b, $acc) β€” computes the numerical integral result of an interpolated function over the range [$a, $b], using $interp, the data arrays $xa and $ya, and the accelerator $acc. returns 0 if it succeeded, 1 otherwise, plus the result value. math girlies rise πŸ˜­πŸ‘‘
  • gsl_interp_eval_integ($interp, $xa, $ya, $a, $b, $acc) β€” returns the numerical integral result of an interpolated function over the range [$a, $b], using $interp, the data arrays $xa and $ya, and the accelerator $acc.
  • gsl_interp_free($interp) β€” frees the interpolation object $interp. clean up after yourself bestie 🧹
  • gsl_interp_bsearch($x_array, $x, $index_lo, $index_hi) β€” returns the index i of the array $x_array such that $x_array[i] <= x < $x_array[i+1]. the index is searched for inside the range [$index_lo,$index_hi]. πŸ”₯

πŸŽ€ the constants πŸŽ€

this module also includes the following constants, and each one has a whole personality:

  • $gsl_interp_linear β€” linear interpolation. simple. clean. no notes. ✨
  • $gsl_interp_polynomial β€” polynomial interpolation. ⚠️ this method should only be used for interpolating small numbers of points, because polynomial interpolation introduces large oscillations, even for well-behaved datasets. the number of terms in the interpolating polynomial is equal to the number of points. like, the drama is structural, not a skill issue. πŸ’€
  • $gsl_interp_cspline β€” cubic spline with natural boundary conditions. the resulting curve is piecewise cubic on each interval, with matching first and second derivatives at the supplied data-points. the second derivative is chosen to be zero at the first point and the last point. πŸ¦‹
  • $gsl_interp_cspline_periodic β€” cubic spline with periodic boundary conditions. the resulting curve is piecewise cubic on each interval, with matching first and second derivatives at the supplied data-points, and the derivatives at the first and last points are also matched. ⚠️ note that the last point in the data must have the same y-value as the first point β€” otherwise the resulting periodic interpolation will have a discontinuity at the boundary. not a vibe. πŸ™ˆ
  • $gsl_interp_akima β€” non-rounded Akima spline with natural boundary conditions. this method uses the non-rounded corner algorithm of Wodicka. πŸ‘‘
  • $gsl_interp_akima_periodic β€” non-rounded Akima spline with periodic boundary conditions. this method uses the non-rounded corner algorithm of Wodicka. same algorithm, periodic energy. πŸ’œ

🌸 AUTHORS 🌸

Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>. legends, both of them, we stan πŸ’–


Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page, bestie 🫢 this one's documented under perl v5.42.3 and dated 2026-08-20, so go forth and interpolate responsibly. slay, periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from