1Math::Derivative(3) User Contributed Perl Documentation Math::Derivative(3)
2
3
4
6 Math::Derivative - Numeric 1st and 2nd order differentiation
7
9 use Math::Derivative qw(:all);
10
11 @dydx = forwarddiff(\@x, \@y);
12
13 @dydx = centraldiff(\@x, \@y);
14
15 @dydx = Derivative1(\@x, \@y); # A synonym for centraldiff()
16
17 @d2ydx2 = Derivative2(\@x, \@y, $yd0, $ydn);
18
20 This Perl package exports functions that numerically approximate first
21 and second order differentiation on vectors of data. The accuracy of
22 the approximation will depend upon the differences between the
23 successive values in the X array.
24
25 FUNCTIONS
26 The functions may be imported by name or by using the tag ":all".
27
28 forwarddiff()
29
30 @dydx = forwarddiff(\@x, \@y);
31
32 Take the references to two arrays containing the x and y ordinates of
33 the data, and return an array of approximate first derivatives at the
34 given x ordinates, using the forward difference approximation.
35
36 The last term is actually formed using a backward difference formula,
37 there being no array item to subtract from at the end of the array. If
38 you want to use derivatives strictly formed from the forward difference
39 formula, use only the values from [0 .. #y-1], e.g.:
40
41 @dydx = (forwarddiff(\@x, \@y))[0 .. $#y-1];
42
43 or, more simply,
44
45 @dydx = forwarddiff(\@x, \@y);
46 pop @dydx;
47
48 centraldiff()
49
50 @dydx = centraldiff(\@x, \@y);
51
52 Take the references to two arrays containing the x and y ordinates of
53 the data, and return an array of approximate first derivatives at the
54 given x ordinates.
55
56 The algorithm used three data points to calculate the derivative,
57 except at the end points, where by necessity the forward difference
58 algorithm is used instead. If you want to use derivatives strictly
59 formed from the central difference formula, use only the values from [1
60 .. #y-1], e.g.:
61
62 @dydx = (centraldiff(\@x, \@y))[1 .. $#y-1];
63
64 Derivative2()
65
66 @d2ydx2 = Derivative2(\@x, \@y);
67
68 or
69
70 @d2ydx2 = Derivative2(\@x, \@y, $yp0, $ypn);
71
72 Take references to two arrays containing the x and y ordinates of the
73 data and return an array of approximate second derivatives at the given
74 x ordinates.
75
76 You may optionally give values to use as the first derivatives at the
77 start and end points of the data. If you don't, first derivative values
78 will be assumed to be zero.
79
80 Derivative1()
81
82 A synonym for centraldiff().
83
85 <http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/central-differences/>
86
87 <http://www.robots.ox.ac.uk/~sjrob/Teaching/EngComp/ecl6.pdf>
88
90 John A.R. Williams J.A.R.Williams@aston.ac.uk
91
92 John M. Gamble jgamble@cpan.org (current maintainer)
93
94
95
96perl v5.34.0 2022-01-21 Math::Derivative(3)