View Full Version : Javascript Derivate Calculator
JonTheGeek 05042004, 06:27 PM I've seen several Java or Perl Derivative Calculators (http://cs.jsu.edu/mcis/faculty/leathrum/Mathlets/derivcalc.html) online, but I can't seem to find any in JavaScript. Has anyone tried? I might need one in JavaScript (or Flash ActionScript) for a graphing tool I'm working on, and I don't want to reinvent the wheel if I can avoid it.
sad69 05042004, 08:18 PM I haven't tried, and I've never looked either! I've never done too much "objectoriented" Javascript, but I did find the source code to the page you posted:
http://cs.jsu.edu/mcis/faculty/leathrum/Mathlets/src/
It's one of the links near the bottom. It might not be the easiest thing to convert as he's got a few different classes, as well as parser built in C. But it's probably doable.
If I had the time, I might even try to tackle it.
There are Derivative Calculators I've found on Google, but they expect numbers, not variables like the one you've posted (which is a cool one I must say!).
Good luck to anyone that tries it, and you should post it on the Post a Javascript forum as it could be useful to others.
Sadiq.
JonTheGeek 05042004, 08:24 PM Hmm, thanks, mostly. It looks like it might be even more complex than I expected it to be. My guess is this won't happen soon (we probably need something that will process faster than this would process), but I'll keep thinking about it, and probably EVENTUALLY do it (I work at an educational technology company, so I'm sure we'll want a derivative calculator EVENTUALLY).
Do you need symbolic differentiation or just numeric? Numeric is easy, for example you can use the common approximation
function diff(f) {
return function(x) { return (f(x+.00001)f(x))/.00001 };
}
And call it like:
function f(x) {
return x*x+2*x+1;
}
fprime = diff(f);
fprime(0.5); // about 1
You can adjust the 0.00001 to a smaller and smaller number to gain accuracy, in theory it becomes precisely correct at an infinitesimally small value close to zero (call it an epsilon). There are also parabolic interpolations you could use, etc.
Even symbolically, differentiation is not that difficult. With a knowledge of the sum, multiplication, power, chain rules, and the deriviatives of elementary functions, you can differentiate precisely any continuous function.
JonTheGeek 05042004, 08:55 PM Do you need symbolic differentiation or just numeric?
Unfortunately, I need symbolic.
Even symbolically, differentiation is not that difficult. With a knowledge of the sum, multiplication, power, chain rules, and the deriviatives of elementary functions, you can differentiate precisely any continuous function.
I know it's not that difficult for ME to do it (or wasn't back when calculus was fresh in my mind), but I'm worried that it might be difficult to JavaScript to do it.
What I'm really hoping to do is to take an input function, find the second derivative, and use it to find inflection points for a graphing program (which will be Flashbased, but will either call this derivative function or include it translated to ActionScript). I'd probably eventually use the function in some other calculus educational products, as well.
Parsing input into symbolic expressions really isn't that difficult in Javascript (that was what I was getting at). This was something I started a while ago for Alex Vincent, never quite finished it, but could easily be completed 100% with a quick replacement of the binary tree with an nary tree...
http://www.jasonkarldavis.com/math/test.xhtml
james.mclellan 09232011, 04:27 PM After going through some of the links here trying to find a tool to fit my own needs, I started a GitHub project to make a public symbolic math javascript library.
It's located here: https://github.com/jamesmclellan/SymbolicMathLibraryforJavascript
And, hopefully, will not be going anywhere as long as GitHub is around.
Presently, it handles: addition, subtraction, multiplication, division, exponents, parentheticals, simple differentials (with and without product rule).
I would be very grateful for contributions to the baseline, if anyone would be so inclined.
martin.donk 09062013, 08:07 PM I know this post is very old but I decided to give it go. I got as far as differentiation and algebraic parsing. I hope to wrap up integration and complex numbers soon. For something like an online plotter or calculator it should do just fine especially since I build in a javascript function exporter.
Take a look and give me some feedback. http://www.nerdamer.com/demo.
The source is at https://github.com/nerdamer/nerdamer/tree/differentiation

