"Fossies" - the Fresh Open Source Software Archive

Member "PDL-2.080/GENERATED/PDL/GSL/DIFF.pm" (28 May 2022, 5148 Bytes) of package /linux/misc/PDL-2.080.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "DIFF.pm" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.079_vs_2.080.

    1 #
    2 # GENERATED WITH PDL::PP! Don't modify!
    3 #
    4 package PDL::GSL::DIFF;
    5 
    6 our @EXPORT_OK = qw(gsldiff diff_central diff_backward diff_forward );
    7 our %EXPORT_TAGS = (Func=>\@EXPORT_OK);
    8 
    9 use PDL::Core;
   10 use PDL::Exporter;
   11 use DynaLoader;
   12 
   13 
   14    
   15    our @ISA = ( 'PDL::Exporter','DynaLoader' );
   16    push @PDL::Core::PP, __PACKAGE__;
   17    bootstrap PDL::GSL::DIFF ;
   18 
   19 
   20 
   21 
   22 
   23 
   24 #line 4 "gsl_diff.pd"
   25 
   26 
   27 use strict;
   28 use warnings;
   29 
   30 =head1 NAME
   31 
   32 PDL::GSL::DIFF - PDL interface to numerical differentiation routines in GSL
   33 
   34 =head1 DESCRIPTION
   35 
   36 This is an interface to the numerical differentiation package present in the 
   37 GNU Scientific Library.
   38 
   39 =head1 SYNOPSIS
   40 
   41    use PDL;
   42    use PDL::GSL::DIFF;
   43 
   44    my $x0 = 3.3;
   45 
   46    my @res = gsldiff(\&myfunction,$x0);
   47    # same as above:
   48    @res = gsldiff(\&myfunction,$x0,{Method => 'central'});
   49 
   50    # use only values greater than $x0 to get the derivative 
   51    @res =  gsldiff(\&myfunction,$x0,{Method => 'forward'});
   52    
   53    # use only values smaller than $x0 to get the derivative 
   54    @res = gsldiff(\&myfunction,$x0,{Method => 'backward'});
   55 
   56    sub myfunction{
   57      my ($x) = @_;
   58      return $x**2;
   59    }
   60 #line 61 "DIFF.pm"
   61 
   62 
   63 
   64 
   65 
   66 
   67 =head1 FUNCTIONS
   68 
   69 =cut
   70 
   71 
   72 
   73 
   74 #line 119 "gsl_diff.pd"
   75 
   76 
   77 sub gsldiff{
   78   my $opt;
   79   if (ref($_[$#_]) eq 'HASH'){ $opt = pop @_; }
   80   else{ $opt = {Method => 'central'}; }
   81   die 'Usage: gsldiff(function_ref, x, {Options} )'
   82       if $#_<1 || $#_>2;
   83   my ($f,$x) = @_;  
   84   my ($res,$abserr);
   85   if($$opt{Method}=~/cent/i){
   86    ($res,$abserr) = PDL::GSL::DIFF::diff_central($x,$f);
   87   }
   88   elsif($$opt{Method}=~/back/i){
   89     ($res,$abserr) = PDL::GSL::DIFF::diff_backward($x,$f);
   90   }
   91   elsif($$opt{Method}=~/forw/i){
   92     ($res,$abserr) = PDL::GSL::DIFF::diff_forward($x,$f);
   93   }
   94   else{
   95     barf("Unknown differentiation method $$opt{Method} in gsldiff\n");
   96   }
   97   return ($res,$abserr);
   98 }
   99 #line 100 "DIFF.pm"
  100 
  101 
  102 
  103 #line 948 "../../../blib/lib/PDL/PP.pm"
  104 
  105 
  106 
  107 =head2 diff_central
  108 
  109 =for sig
  110 
  111   Signature: (double x(); double [o] res(); double [o] abserr(); SV* function)
  112 
  113 
  114 =for ref
  115 
  116 info not available
  117 
  118 
  119 =for bad
  120 
  121 diff_central does not process bad values.
  122 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
  123 
  124 
  125 =cut
  126 #line 127 "DIFF.pm"
  127 
  128 
  129 
  130 #line 950 "../../../blib/lib/PDL/PP.pm"
  131 
  132 *diff_central = \&PDL::diff_central;
  133 #line 134 "DIFF.pm"
  134 
  135 
  136 
  137 #line 948 "../../../blib/lib/PDL/PP.pm"
  138 
  139 
  140 
  141 =head2 diff_backward
  142 
  143 =for sig
  144 
  145   Signature: (double x(); double [o] res(); double [o] abserr(); SV* function)
  146 
  147 
  148 =for ref
  149 
  150 info not available
  151 
  152 
  153 =for bad
  154 
  155 diff_backward does not process bad values.
  156 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
  157 
  158 
  159 =cut
  160 #line 161 "DIFF.pm"
  161 
  162 
  163 
  164 #line 950 "../../../blib/lib/PDL/PP.pm"
  165 
  166 *diff_backward = \&PDL::diff_backward;
  167 #line 168 "DIFF.pm"
  168 
  169 
  170 
  171 #line 948 "../../../blib/lib/PDL/PP.pm"
  172 
  173 
  174 
  175 =head2 diff_forward
  176 
  177 =for sig
  178 
  179   Signature: (double x(); double [o] res(); double [o] abserr(); SV* function)
  180 
  181 
  182 =for ref
  183 
  184 info not available
  185 
  186 
  187 =for bad
  188 
  189 diff_forward does not process bad values.
  190 It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
  191 
  192 
  193 =cut
  194 #line 195 "DIFF.pm"
  195 
  196 
  197 
  198 #line 950 "../../../blib/lib/PDL/PP.pm"
  199 
  200 *diff_forward = \&PDL::diff_forward;
  201 #line 202 "DIFF.pm"
  202 
  203 
  204 
  205 
  206 
  207 #line 41 "gsl_diff.pd"
  208 
  209 =head2 gsldiff
  210 
  211 =for ref
  212 
  213 This functions serves as an interface to the three differentiation 
  214 functions present in GSL: gsl_diff_central, gsl_diff_backward and 
  215 gsl_diff_forward. To compute the derivative, the central method uses 
  216 values greater and smaller than the point at which the derivative is 
  217 to be evaluated, while backward and forward use only values smaller 
  218 and greater respectively. gsldiff() returns both the derivative 
  219 and an absolute error estimate. The default  method is 'central', 
  220 others can be specified by passing an option.
  221 
  222 Please check the GSL documentation for more information.
  223 
  224 =for usage
  225 
  226 Usage:
  227 
  228   ($d,$abserr) = gsldiff($function_ref,$x,{Method => $method});
  229 
  230 =for example
  231 
  232 Example:
  233 
  234   #derivative using default method ('central')
  235   ($d,$abserr) = gsldiff(\&myf,3.3);
  236 
  237   #same as above with method set explicitly
  238   ($d,$abserr) = gsldiff(\&myf,3.3,{Method => 'central'});
  239 
  240   #using backward & forward methods
  241   ($d,$abserr) = gsldiff(\&myf,3.3,{Method => 'backward'});
  242   ($d,$abserr) = gsldiff(\&myf,3.3,{Method => 'forward'});
  243 
  244   sub myf{
  245     my ($x) = @_;
  246     return exp($x);
  247   }
  248 
  249 =head1 BUGS
  250 
  251 Feedback is welcome. Log bugs in the PDL bug database (the
  252 database is always linked from L<http://pdl.perl.org>).
  253 
  254 =head1 SEE ALSO
  255 
  256 L<PDL>
  257 
  258 The GSL documentation is online at
  259 
  260   http://www.gnu.org/software/gsl/manual/
  261 
  262 =head1 AUTHOR
  263 
  264 This file copyright (C) 2003 Andres Jordan <andresj@physics.rutgers.edu>
  265 All rights reserved. There is no warranty. You are allowed to redistribute 
  266 this software documentation under certain conditions. For details, see the file
  267 COPYING in the PDL distribution. If this file is separated from the
  268 PDL distribution, the copyright notice should be included in the file.
  269 
  270 The GSL differentiation routines were written by David Morrison.
  271 
  272 =cut
  273 #line 274 "DIFF.pm"
  274 
  275 
  276 
  277 
  278 # Exit with OK status
  279 
  280 1;