Created
June 17, 2011 20:43
-
-
Save guipn/1032298 to your computer and use it in GitHub Desktop.
Numeric Derivative
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function derivator(func, step) { | |
step = step || Number.MIN_VALUE; | |
return function (x) { | |
return (func(x + step) - func(x)) / step; | |
}; | |
} | |
// As simple as that. | |
// | |
// var derive = derivator(function(x) { return x * x; }, 1e-10); | |
// | |
// derive(1) now (approximately) equals the derivative of x^2 for x = 1. The smaller the step, | |
// the closer the approximation. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment