DIFFSection: User Contributed Perl Documentation (3)Updated: 2004-06-15 |
DIFFSection: User Contributed Perl Documentation (3)Updated: 2004-06-15 |
use PDL; use PDL::GSL::DIFF;
my $x0 = 3.3;
my @res = gsldiff(\&myfunction,$x0);
# same as above:
@res = gsldiff(\&myfunction,$x0,{Method => 'central'});
# use only values greater than $x0 to get the derivative
@res = gsldiff(\&myfunction,$x0,{Method => 'forward'});
# use only values smaller than $x0 to get the derivative
@res = gsldiff(\&myfunction,$x0,{Method => 'backward'});
sub myfunction{
my ($x) = @_;
return $x**2;
}
Please check the GSL documentation for more information.
Usage:
($d,$abserr) = gsldiff($function_ref,$x,{Method => $method});
Example:
#derivative using default method ('central')
($d,$abserr) = gsldiff(\&myf,3.3);
#same as above with method set explicitly
($d,$abserr) = gsldiff(\&myf,3.3,{Method => 'central'});
#using backward & forward methods
($d,$abserr) = gsldiff(\&myf,3.3,{Method => 'backward'});
($d,$abserr) = gsldiff(\&myf,3.3,{Method => 'forward'});
sub myf{
my ($x) = @_;
return exp($x);
}
The GSL documentation is online at
http://sources.redhat.com/gsl/ref/gsl-ref_toc.html
The GSL differentiation routines were written by David Morrison.
Signature: (double x(); double [o] res(); double [o] abserr(); SV* funcion)
Signature: (double x(); double [o] res(); double [o] abserr(); SV* funcion)
Signature: (double x(); double [o] res(); double [o] abserr(); SV* funcion)
info not available