Math-Derivative
view release on metacpan or search on metacpan
lib/Math/Derivative.pm view on Meta::CPAN
The functions may be imported by name or by using the tag ":all".
=head3 forwarddiff()
@dydx = forwarddiff(\@x, \@y);
Take the references to two arrays containing the x and y ordinates of
the data, and return an array of approximate first derivatives at the
given x ordinates, using the forward difference approximation.
The last term is actually formed using a backward difference formula,
there being no array item to subtract from at the end of the array.
If you want to use derivatives strictly formed from the forward
difference formula, use only the values from [0 .. #y-1], e.g.:
@dydx = (forwarddiff(\@x, \@y))[0 .. $#y-1];
or, more simply,
@dydx = forwarddiff(\@x, \@y);
pop @dydx;
=cut
lib/Math/Derivative.pm view on Meta::CPAN
@dydx = centraldiff(\@x, \@y);
Take the references to two arrays containing the x and y ordinates of
the data, and return an array of approximate first derivatives at the
given x ordinates.
The algorithm used three data points to calculate the derivative, except
at the end points, where by necessity the forward difference algorithm
is used instead. If you want to use derivatives strictly formed from
the central difference formula, use only the values from [1 .. #y-1],
e.g.:
@dydx = (centraldiff(\@x, \@y))[1 .. $#y-1];
=cut
sub centraldiff
{
my($x, $y) = @_;
my @y2;
( run in 0.692 second using v1.01-cache-2.11-cpan-26ccb49234f )