Math::Derivative(3pm)

πŸ“¦
version 1.01 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

✨ Math::Derivative ✨ (that's the Math::Derivative(3pm) page, bestie β€” user contributed Perl docs, and yes we're doing this πŸ’–)

okay so picture this: you've got data, you want derivatives, and you do NOT wanna do calculus by hand. enter this little Perl package. numeric first and second order differentiation, that's the whole vibe.


🌸 NAME 🌸

Math::Derivative β€” numeric 1st and 2nd order differentiation πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

use Math::Derivative qw(:all);

@dydx = forwarddiff(\@x, \@y);

@dydx = centraldiff(\@x, \@y);

@dydx = Derivative1(\@x, \@y);     # A synonym for centraldiff()

@d2ydx2 = Derivative2(\@x, \@y, $yd0, $ydn);

look at that. four whole ways to get your derivative on. iconic behavior honestly.


πŸ’œ DESCRIPTION πŸ’œ

This Perl package exports functions that numerically approximate first and second order differentiation on vectors of data. literally that's it, that's the job.

heads up tho: how accurate your approximation is depends on the differences between the successive values in the X array. small gaps = happy math. big weird gaps = your results are gonna be giving ✨chaos✨.


πŸŽ€ FUNCTIONS πŸŽ€

You can import these functions by name, or just grab the whole squad with the :all tag. no cap.


πŸ“ forwarddiff()

@dydx = forwarddiff(\@x, \@y);

Take the references to two arrays containing the x and y ordinates of the data, and it hands you back an array of approximate first derivatives at the given x ordinates, using the forward difference approximation. slay.

now the tea β˜•: that last term is actually formed using a backward difference formula, because there is no array item to subtract from at the end of the array. poor thing is at the edge of the party with nobody to subtract.

so if you want derivatives strictly formed from the forward difference formula, use only the values from [0 .. #y-1], like:

@dydx = (forwarddiff(\@x, \@y))[0 .. $#y-1];

or, more simply:

@dydx = forwarddiff(\@x, \@y);
pop @dydx;

pop it like it's hot πŸ”₯


🧚 centraldiff()

@dydx = centraldiff(\@x, \@y);

Take the references to two arrays containing the x and y ordinates of the data, and it returns an array of approximate first derivatives at the given x ordinates. bestie behavior.

the algorithm uses three data points to calculate the derivative β€” except at the end points, where by necessity the forward difference algorithm is used instead. the ends are just doing their best okay 😭

if you want derivatives strictly formed from the central difference formula, use only the values from [1 .. #y-1], like:

@dydx = (centraldiff(\@x, \@y))[1 .. $#y-1];

slicing off the ends so they can't ruin the vibe πŸ’…


🌈 Derivative2()

@d2ydx2 = Derivative2(\@x, \@y);

or

@d2ydx2 = Derivative2(\@x, \@y, $yp0, $ypn);

Take references to two arrays containing the x and y ordinates of the data and it returns an array of approximate second derivatives at the given x ordinates. second derivative era fr fr.

you may optionally give values to use as the first derivatives at the start and end points of the data. if you don't, first derivative values will be assumed to be zero. so like, speak now or forever hold your zeros.


πŸ‘‘ Derivative1()

A synonym for centraldiff(). same function, second name, main character energy. 😌


⭐ REFERENCES ⭐

the receipts, the lore, the required reading πŸ“šβœ¨


πŸ’– AUTHOR πŸ’–

  • John A.R. Williams β€” J.A.R.Williams@aston.ac.uk
  • John M. Gamble β€” jgamble@cpan.org (current maintainer)

shoutout to the maintainers, holding it down 🫢


and that's the whole page, bestie! go forth and differentiate. numerically. responsibly. πŸ’…βœ¨

this was Math::Derivative(3pm) from perl v5.36.0, dated 2022-10-13 β€” mwah, kisses, bye πŸ’‹

πŸ“¦ where this page comes from