Math::GSL::Deriv(3pm)
π Math::GSL::Deriv π
okay bestie, welcome to Math::GSL::Deriv(3pm) β it's filed under User Contributed Perl Documentation and it's literally your girl for Numerical Derivatives. yes, the module name is Math::GSL::Deriv, that's the whole brand, no notes. π
β¨ SYNOPSIS β¨
use Math::GSL::Deriv qw/:all/;
use Math::GSL::Errno qw/:all/;
my ($x, $h) = (1.5, 0.01);
my ($status, $val,$err) = gsl_deriv_central ( sub { sin($_[0]) }, $x, $h);
my $res = abs($val - cos($x));
if ($status == $GSL_SUCCESS) {
printf "deriv(sin((%g)) = %.18g, max error=%.18g\n", $x, $val, $err;
printf " cos(%g)) = %.18g, residue= %.18g\n" , $x, cos($x), $res;
} else {
my $gsl_error = gsl_strerror($status);
print "Numerical Derivative FAILED, reason:\n $gsl_error\n\n";
}
πΈ DESCRIPTION πΈ
so here's the vibe: this module lets you take the numerical derivative of a Perl subroutine. iconic, right? π¦
to actually find one, you also gotta hand over a point to evaluate the derivative at, plus a "step size". think of the step size as a lil knob you can twist to get a more finely grained or more coarse grained approximation β it's giving volume dial but for math. as the step size $h goes to zero, you reach the formal definition of a derivative, but in practice you gotta pick a reasonable step size to get a reasonable answer. usually anything in the range of 1/10 to 1/10000 is sufficient, no cap. β¨
and the best part? so long as your function returns a single scalar value, you can differentiate as complicated a function as your heart desires. π
gsl_deriv_central($function, $x, $h)
use Math::GSL::Deriv qw/gsl_deriv_central/;
my ($x, $h) = (1.5, 0.01);
sub func { my $x=shift; $x**4 - 15 * $x + sqrt($x) };
my ($status, $val,$err) = gsl_deriv_central ( \&func , $x, $h);
this method approximates the central difference of the subroutine reference $function, evaluated at $x, with "step size" $h. translation? the function gets evaluated at $x-$h and $x+h. both sides get a turn, main character behavior honestly π
gsl_deriv_backward($function, $x, $h)
use Math::GSL::Deriv qw/gsl_deriv_backward/;
my ($x, $h) = (1.5, 0.01);
sub func { my $x=shift; $x**4 - 15 * $x + sqrt($x) };
my ($status, $val,$err) = gsl_deriv_backward ( \&func , $x, $h);
this one approximates the backward difference of the subroutine reference $function, evaluated at $x, with "step size" $h. meaning: the function is evaluated at $x-$h and $x. it's looking back, respectfully π«Ά
gsl_deriv_forward($function, $x, $h)
use Math::GSL::Deriv qw/gsl_deriv_forward/;
my ($x, $h) = (1.5, 0.01);
sub func { my $x=shift; $x**4 - 15 * $x + sqrt($x) };
my ($status, $val,$err) = gsl_deriv_forward ( \&func , $x, $h);
and this babe approximates the forward difference</forward> of the subroutine reference $function, evaluated at $x, with "step size" $h. so the function is evaluated at $x and $x+$h. eyes on the future, periodt π₯
For more information on the functions, we refer you to the GSL official documentation: http://www.gnu.org/software/gsl/manual/html_node/
π AUTHORS π
Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
π COPYRIGHT AND LICENSE π
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 little gift was served up by perl v5.42.3 on 2026-08-20, and yeah, that's Math::GSL::Deriv(3pm) doing the absolute most. go take some derivatives, you got this, mwah πβ¨π
π¦ where this page comes from
- ubuntu stonking: libmath-gsl-perl 0.49-1build1 Β· 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