I am desperately looking for a JavaScript that can calculate the first derivative of a function. The function always includes only one variable, x.
e.g. f(x) = x² f'(3) = 2x
Consequently, the script should deliver the result 6, since 2*3 = 6
.
I hope you know what I mean.
Computing DerivativesFind f(x + h). Plug f(x + h), f(x), and h into the limit definition of a derivative. Simplify the difference quotient. Take the limit, as h approaches 0, of the simplified difference quotient.
In R programming, derivative of a function can be computed using deriv() and D() function. It is used to compute derivatives of simple expressions.
function slope (f, x, dx) {
dx = dx || .0000001;
return (f(x+dx) - f(x)) / dx;
}
var f = function (x) { return Math.pow(x, 2); }
slope(f, 3)
Here's a Java library to help do such a thing:
http://jscl-meditor.sourceforge.net/
And another:
http://www.mathtools.net/Java/Mathematics/index.html
You can always use Rhino and import Java classes to use in your JavaScript.
Here's one for JavaScript:
http://code.google.com/p/smath/wiki/smathJavaScriptAPI
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With