Jonathan Leto > Math-GSL > Math::GSL::Deriv

Download:
Math-GSL-0.28.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  8
Open  8
View/Report Bugs
Source   Latest Release: Math-GSL-0.34

NAME ^

Math::GSL::Deriv - Numerical Derivatives

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 ^

This module allows you to take the numerical derivative of a Perl subroutine. To find a numerical derivative you must also specify a point to evaluate the derivative and a "step size". The step size is a knob that you can turn to get a more finely or coarse grained approximation. As the step size $h goes to zero, the formal definition of a derivative is reached, but in practive you must choose a reasonable step size to get a reasonable answer. Usually something in the range of 1/10 to 1/10000 is sufficient.

So long as your function returns a single scalar value, you can differentiate as complicated a function as your heart desires.

For more informations on the functions, we refer you to the GSL offcial 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-2011 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.

syntax highlighting: