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