3 use Math
::GSL
::Deriv qw
/:all/;
4 use Math
::GSL
::Errno qw
/:all/;
6 # This is a numerical verification of the mathematical fact
7 # that the derivative of sin(x) is cos(x), i.e.
10 # -( sin(x) ) = cos(x)
13 my ($x, $h) = (1.5, 0.01);
14 my ($status, $val,$err) = gsl_deriv_central
( sub { sin($_[0]) }, $x, $h);
15 my $res = abs($val - cos($x));
16 if ($status == $GSL_SUCCESS) {
17 printf "deriv(sin((%g)) = %.18g, max error=%.18g\n", $x, $val, $err;
18 printf " cos(%g)) = %.18g, residue= %.18g\n" , $x, cos($x), $res;
20 my $gsl_error = gsl_strerror
($status);
21 print "Numerical Derivative FAILED, reason:\n $gsl_error\n\n";