Differentiation or Indefinite Integration in PHP, Javascript, or C#? [duplicate]
I think/thought my question is rather simple, but I don't seem to be finding answers (yes I did pleny of Googleing). What I want t do is to be able to differentiate or integrate dynamically given an equation. For example:
diff((x^2)/(15*x^4-32*x^5),x)
Would Return:
20*(8*x^4 - 3*x^3)*x^2/(32*x^5 - 15*x^4)^2 - 2*x/(32*x^5 - 15*x^4)
I know PHP, JavaScript and C#, so any work, but I really need some kind of software that can do this. I tried SAGE, but it is more of a server then a software, plus it is in python.
If I could even get some keywords to Google, that would be helpful as well.
Thanks in advance for开发者_如何转开发 any replies!
Since none of the answers mention a JavaScript solution. I give it a shot.
Try nerdamer .
It has lots of integration and differentiation methods.
//Derivative of (x^2)/(15*x^4-32*x^5)
var result = nerdamer('diff((x^2)/(15*x^4-32*x^5),x)').evaluate();
document.getElementById('text').innerHTML = '<p>'+result.text()+'</p>';
//Derivative of sin(x^2) + log(x) - 23 + e^(cos(x))
result = nerdamer('diff(sin(x^2)+log(x)-23+exp(cos(x)),x)').evaluate();
document.getElementById('text').innerHTML += '<p>'+result.text()+'</p>';
<script src="http://nerdamer.com/js/nerdamer.core.js"></script>
<script src="http://nerdamer.com/js/Algebra.js"></script>
<script src="http://nerdamer.com/js/Calculus.js"></script>
<div id="text"></div>
You might want to try Googling for computer-algebra systems / libraries, of which SAGE is one example. There are others, such as Maxima and Axiom. There is a list on Wikipedia. If none of these are suitable, you could always try calling Wolfram Alpha.
Because for derivatives we have...
- sum/difference rules
- constant multiple rules
- product rule
- quotient rule
- chain rule
- exponent rule (or trick, depending on how you're taught)
...it's possible to calculate the derivative of a formula from its parse tree, by recursive application of these combinative rules. This makes a very nice exercise for beginners. The exercise includes parsing, calculus, recursion, etc.
For integrals, we have many tricks analogous to (and derived from) those rules, but we lack:
- a product rule for integral(f(x)*g(x)) directly in terms of integral(f) and integral(g)
- a composition rule for integral(f(g(x))) directly in terms of integral(f) and integral(g)
- a quotient rule for integral(f(x)/g(x)) in terms of integral(f) and integral(g)
(integration by parts is not #1! substitution is not #2!)
For these reasons, integration is fundamentally harder than differentiation.
You can expect simple packages to do differentiation quite well. But effective, robust symbolic integration is difficult to come by. For good integration, turn to the experts: Maple, Mathematica, Sage, Alpha, etc.
If you can make HTTP requests and use an external API, consider SaturnAPI. It uses Octave/Matlab code. The linked example is integrating a differential equation.
精彩评论