1# This file was automatically generated by SWIG (http://www.swig.org). 2# Version 4.0.1 3# 4# Do not make changes to this file unless you know what you are doing--modify 5# the SWIG interface file instead. 6 7package Math::GSL::Deriv; 8use base qw(Exporter); 9use base qw(DynaLoader); 10package Math::GSL::Derivc; 11bootstrap Math::GSL::Deriv; 12package Math::GSL::Deriv; 13@EXPORT = qw(); 14 15# ---------- BASE METHODS ------------- 16 17package Math::GSL::Deriv; 18 19sub TIEHASH { 20 my ($classname,$obj) = @_; 21 return bless $obj, $classname; 22} 23 24sub CLEAR { } 25 26sub FIRSTKEY { } 27 28sub NEXTKEY { } 29 30sub FETCH { 31 my ($self,$field) = @_; 32 my $member_func = "swig_${field}_get"; 33 $self->$member_func(); 34} 35 36sub STORE { 37 my ($self,$field,$newval) = @_; 38 my $member_func = "swig_${field}_set"; 39 $self->$member_func($newval); 40} 41 42sub this { 43 my $ptr = shift; 44 return tied(%$ptr); 45} 46 47 48# ------- FUNCTION WRAPPERS -------- 49 50package Math::GSL::Deriv; 51 52*gsl_error = *Math::GSL::Derivc::gsl_error; 53*gsl_stream_printf = *Math::GSL::Derivc::gsl_stream_printf; 54*gsl_strerror = *Math::GSL::Derivc::gsl_strerror; 55*gsl_set_error_handler = *Math::GSL::Derivc::gsl_set_error_handler; 56*gsl_set_error_handler_off = *Math::GSL::Derivc::gsl_set_error_handler_off; 57*gsl_set_stream_handler = *Math::GSL::Derivc::gsl_set_stream_handler; 58*gsl_set_stream = *Math::GSL::Derivc::gsl_set_stream; 59*gsl_deriv_central = *Math::GSL::Derivc::gsl_deriv_central; 60*gsl_deriv_backward = *Math::GSL::Derivc::gsl_deriv_backward; 61*gsl_deriv_forward = *Math::GSL::Derivc::gsl_deriv_forward; 62 63############# Class : Math::GSL::Deriv::gsl_function_struct ############## 64 65package Math::GSL::Deriv::gsl_function_struct; 66use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); 67@ISA = qw( Math::GSL::Deriv ); 68%OWNER = (); 69%ITERATORS = (); 70*swig_function_get = *Math::GSL::Derivc::gsl_function_struct_function_get; 71*swig_function_set = *Math::GSL::Derivc::gsl_function_struct_function_set; 72*swig_params_get = *Math::GSL::Derivc::gsl_function_struct_params_get; 73*swig_params_set = *Math::GSL::Derivc::gsl_function_struct_params_set; 74sub new { 75 my $pkg = shift; 76 my $self = Math::GSL::Derivc::new_gsl_function_struct(@_); 77 bless $self, $pkg if defined($self); 78} 79 80sub DESTROY { 81 return unless $_[0]->isa('HASH'); 82 my $self = tied(%{$_[0]}); 83 return unless defined $self; 84 delete $ITERATORS{$self}; 85 if (exists $OWNER{$self}) { 86 Math::GSL::Derivc::delete_gsl_function_struct($self); 87 delete $OWNER{$self}; 88 } 89} 90 91sub DISOWN { 92 my $self = shift; 93 my $ptr = tied(%$self); 94 delete $OWNER{$ptr}; 95} 96 97sub ACQUIRE { 98 my $self = shift; 99 my $ptr = tied(%$self); 100 $OWNER{$ptr} = 1; 101} 102 103 104############# Class : Math::GSL::Deriv::gsl_function_fdf_struct ############## 105 106package Math::GSL::Deriv::gsl_function_fdf_struct; 107use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); 108@ISA = qw( Math::GSL::Deriv ); 109%OWNER = (); 110%ITERATORS = (); 111*swig_f_get = *Math::GSL::Derivc::gsl_function_fdf_struct_f_get; 112*swig_f_set = *Math::GSL::Derivc::gsl_function_fdf_struct_f_set; 113*swig_df_get = *Math::GSL::Derivc::gsl_function_fdf_struct_df_get; 114*swig_df_set = *Math::GSL::Derivc::gsl_function_fdf_struct_df_set; 115*swig_fdf_get = *Math::GSL::Derivc::gsl_function_fdf_struct_fdf_get; 116*swig_fdf_set = *Math::GSL::Derivc::gsl_function_fdf_struct_fdf_set; 117*swig_params_get = *Math::GSL::Derivc::gsl_function_fdf_struct_params_get; 118*swig_params_set = *Math::GSL::Derivc::gsl_function_fdf_struct_params_set; 119sub new { 120 my $pkg = shift; 121 my $self = Math::GSL::Derivc::new_gsl_function_fdf_struct(@_); 122 bless $self, $pkg if defined($self); 123} 124 125sub DESTROY { 126 return unless $_[0]->isa('HASH'); 127 my $self = tied(%{$_[0]}); 128 return unless defined $self; 129 delete $ITERATORS{$self}; 130 if (exists $OWNER{$self}) { 131 Math::GSL::Derivc::delete_gsl_function_fdf_struct($self); 132 delete $OWNER{$self}; 133 } 134} 135 136sub DISOWN { 137 my $self = shift; 138 my $ptr = tied(%$self); 139 delete $OWNER{$ptr}; 140} 141 142sub ACQUIRE { 143 my $self = shift; 144 my $ptr = tied(%$self); 145 $OWNER{$ptr} = 1; 146} 147 148 149############# Class : Math::GSL::Deriv::gsl_function_vec_struct ############## 150 151package Math::GSL::Deriv::gsl_function_vec_struct; 152use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS); 153@ISA = qw( Math::GSL::Deriv ); 154%OWNER = (); 155%ITERATORS = (); 156*swig_function_get = *Math::GSL::Derivc::gsl_function_vec_struct_function_get; 157*swig_function_set = *Math::GSL::Derivc::gsl_function_vec_struct_function_set; 158*swig_params_get = *Math::GSL::Derivc::gsl_function_vec_struct_params_get; 159*swig_params_set = *Math::GSL::Derivc::gsl_function_vec_struct_params_set; 160sub new { 161 my $pkg = shift; 162 my $self = Math::GSL::Derivc::new_gsl_function_vec_struct(@_); 163 bless $self, $pkg if defined($self); 164} 165 166sub DESTROY { 167 return unless $_[0]->isa('HASH'); 168 my $self = tied(%{$_[0]}); 169 return unless defined $self; 170 delete $ITERATORS{$self}; 171 if (exists $OWNER{$self}) { 172 Math::GSL::Derivc::delete_gsl_function_vec_struct($self); 173 delete $OWNER{$self}; 174 } 175} 176 177sub DISOWN { 178 my $self = shift; 179 my $ptr = tied(%$self); 180 delete $OWNER{$ptr}; 181} 182 183sub ACQUIRE { 184 my $self = shift; 185 my $ptr = tied(%$self); 186 $OWNER{$ptr} = 1; 187} 188 189 190# ------- VARIABLE STUBS -------- 191 192package Math::GSL::Deriv; 193 194*GSL_VERSION = *Math::GSL::Derivc::GSL_VERSION; 195*GSL_MAJOR_VERSION = *Math::GSL::Derivc::GSL_MAJOR_VERSION; 196*GSL_MINOR_VERSION = *Math::GSL::Derivc::GSL_MINOR_VERSION; 197*GSL_POSZERO = *Math::GSL::Derivc::GSL_POSZERO; 198*GSL_NEGZERO = *Math::GSL::Derivc::GSL_NEGZERO; 199*GSL_SUCCESS = *Math::GSL::Derivc::GSL_SUCCESS; 200*GSL_FAILURE = *Math::GSL::Derivc::GSL_FAILURE; 201*GSL_CONTINUE = *Math::GSL::Derivc::GSL_CONTINUE; 202*GSL_EDOM = *Math::GSL::Derivc::GSL_EDOM; 203*GSL_ERANGE = *Math::GSL::Derivc::GSL_ERANGE; 204*GSL_EFAULT = *Math::GSL::Derivc::GSL_EFAULT; 205*GSL_EINVAL = *Math::GSL::Derivc::GSL_EINVAL; 206*GSL_EFAILED = *Math::GSL::Derivc::GSL_EFAILED; 207*GSL_EFACTOR = *Math::GSL::Derivc::GSL_EFACTOR; 208*GSL_ESANITY = *Math::GSL::Derivc::GSL_ESANITY; 209*GSL_ENOMEM = *Math::GSL::Derivc::GSL_ENOMEM; 210*GSL_EBADFUNC = *Math::GSL::Derivc::GSL_EBADFUNC; 211*GSL_ERUNAWAY = *Math::GSL::Derivc::GSL_ERUNAWAY; 212*GSL_EMAXITER = *Math::GSL::Derivc::GSL_EMAXITER; 213*GSL_EZERODIV = *Math::GSL::Derivc::GSL_EZERODIV; 214*GSL_EBADTOL = *Math::GSL::Derivc::GSL_EBADTOL; 215*GSL_ETOL = *Math::GSL::Derivc::GSL_ETOL; 216*GSL_EUNDRFLW = *Math::GSL::Derivc::GSL_EUNDRFLW; 217*GSL_EOVRFLW = *Math::GSL::Derivc::GSL_EOVRFLW; 218*GSL_ELOSS = *Math::GSL::Derivc::GSL_ELOSS; 219*GSL_EROUND = *Math::GSL::Derivc::GSL_EROUND; 220*GSL_EBADLEN = *Math::GSL::Derivc::GSL_EBADLEN; 221*GSL_ENOTSQR = *Math::GSL::Derivc::GSL_ENOTSQR; 222*GSL_ESING = *Math::GSL::Derivc::GSL_ESING; 223*GSL_EDIVERGE = *Math::GSL::Derivc::GSL_EDIVERGE; 224*GSL_EUNSUP = *Math::GSL::Derivc::GSL_EUNSUP; 225*GSL_EUNIMPL = *Math::GSL::Derivc::GSL_EUNIMPL; 226*GSL_ECACHE = *Math::GSL::Derivc::GSL_ECACHE; 227*GSL_ETABLE = *Math::GSL::Derivc::GSL_ETABLE; 228*GSL_ENOPROG = *Math::GSL::Derivc::GSL_ENOPROG; 229*GSL_ENOPROGJ = *Math::GSL::Derivc::GSL_ENOPROGJ; 230*GSL_ETOLF = *Math::GSL::Derivc::GSL_ETOLF; 231*GSL_ETOLX = *Math::GSL::Derivc::GSL_ETOLX; 232*GSL_ETOLG = *Math::GSL::Derivc::GSL_ETOLG; 233*GSL_EOF = *Math::GSL::Derivc::GSL_EOF; 234*M_E = *Math::GSL::Derivc::M_E; 235*M_LOG2E = *Math::GSL::Derivc::M_LOG2E; 236*M_LOG10E = *Math::GSL::Derivc::M_LOG10E; 237*M_SQRT2 = *Math::GSL::Derivc::M_SQRT2; 238*M_SQRT1_2 = *Math::GSL::Derivc::M_SQRT1_2; 239*M_SQRT3 = *Math::GSL::Derivc::M_SQRT3; 240*M_PI = *Math::GSL::Derivc::M_PI; 241*M_PI_2 = *Math::GSL::Derivc::M_PI_2; 242*M_PI_4 = *Math::GSL::Derivc::M_PI_4; 243*M_SQRTPI = *Math::GSL::Derivc::M_SQRTPI; 244*M_2_SQRTPI = *Math::GSL::Derivc::M_2_SQRTPI; 245*M_1_PI = *Math::GSL::Derivc::M_1_PI; 246*M_2_PI = *Math::GSL::Derivc::M_2_PI; 247*M_LN10 = *Math::GSL::Derivc::M_LN10; 248*M_LN2 = *Math::GSL::Derivc::M_LN2; 249*M_LNPI = *Math::GSL::Derivc::M_LNPI; 250*M_EULER = *Math::GSL::Derivc::M_EULER; 251 252@EXPORT_OK = qw/ 253 gsl_deriv_central 254 gsl_deriv_backward 255 gsl_deriv_forward 256 /; 257%EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); 258 259__END__ 260 261=encoding utf8 262 263=head1 NAME 264 265Math::GSL::Deriv - Numerical Derivatives 266 267=head1 SYNOPSIS 268 269 use Math::GSL::Deriv qw/:all/; 270 use Math::GSL::Errno qw/:all/; 271 272 my ($x, $h) = (1.5, 0.01); 273 my ($status, $val,$err) = gsl_deriv_central ( sub { sin($_[0]) }, $x, $h); 274 my $res = abs($val - cos($x)); 275 if ($status == $GSL_SUCCESS) { 276 printf "deriv(sin((%g)) = %.18g, max error=%.18g\n", $x, $val, $err; 277 printf " cos(%g)) = %.18g, residue= %.18g\n" , $x, cos($x), $res; 278 } else { 279 my $gsl_error = gsl_strerror($status); 280 print "Numerical Derivative FAILED, reason:\n $gsl_error\n\n"; 281 } 282 283 284=head1 DESCRIPTION 285 286This module allows you to take the numerical derivative of a Perl subroutine. To find 287a numerical derivative you must also specify a point to evaluate the derivative and a 288"step size". The step size is a knob that you can turn to get a more finely or coarse 289grained approximation. As the step size $h goes to zero, the formal definition of a 290derivative is reached, but in practive you must choose a reasonable step size to get 291a reasonable answer. Usually something in the range of 1/10 to 1/10000 is sufficient. 292 293So long as your function returns a single scalar value, you can differentiate as 294complicated a function as your heart desires. 295 296=over 297 298=item * C<gsl_deriv_central($function, $x, $h)> 299 300 use Math::GSL::Deriv qw/gsl_deriv_central/; 301 my ($x, $h) = (1.5, 0.01); 302 sub func { my $x=shift; $x**4 - 15 * $x + sqrt($x) }; 303 304 my ($status, $val,$err) = gsl_deriv_central ( \&func , $x, $h); 305 306This method approximates the central difference of the subroutine reference 307$function, evaluated at $x, with "step size" $h. This means that the 308function is evaluated at $x-$h and $x+h. 309 310 311=item * C<gsl_deriv_backward($function, $x, $h)> 312 313 use Math::GSL::Deriv qw/gsl_deriv_backward/; 314 my ($x, $h) = (1.5, 0.01); 315 sub func { my $x=shift; $x**4 - 15 * $x + sqrt($x) }; 316 317 my ($status, $val,$err) = gsl_deriv_backward ( \&func , $x, $h); 318 319This method approximates the backward difference of the subroutine 320reference $function, evaluated at $x, with "step size" $h. This means that 321the function is evaluated at $x-$h and $x. 322 323=item * C<gsl_deriv_forward($function, $x, $h)> 324 325 use Math::GSL::Deriv qw/gsl_deriv_forward/; 326 my ($x, $h) = (1.5, 0.01); 327 sub func { my $x=shift; $x**4 - 15 * $x + sqrt($x) }; 328 329 my ($status, $val,$err) = gsl_deriv_forward ( \&func , $x, $h); 330 331This method approximates the forward difference of the subroutine reference 332$function, evaluated at $x, with "step size" $h. This means that the 333function is evaluated at $x and $x+$h. 334 335=back 336 337For more informations on the functions, we refer you to the GSL official 338documentation: L<http://www.gnu.org/software/gsl/manual/html_node/> 339 340=head1 AUTHORS 341 342Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com> 343 344=head1 COPYRIGHT AND LICENSE 345 346Copyright (C) 2008-2021 Jonathan "Duke" Leto and Thierry Moisan 347 348This program is free software; you can redistribute it and/or modify it 349under the same terms as Perl itself. 350 351=cut 352 3531; 354