开发者

Differentiation or Indefinite Integration in PHP, Javascript, or C#? [duplicate]

开发者 https://www.devze.com 2023-01-24 18:22 出处:网络
This question already has answers here: OpenSouce C/C++ Math expression parser Library [closed] (7 answers)
This question already has answers here: OpenSouce C/C++ Math expression parser Library [closed] (7 answers) Closed 4 years ago.

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...

  1. sum/difference rules
  2. constant multiple rules
  3. product rule
  4. quotient rule
  5. chain rule
  6. 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:

  1. a product rule for integral(f(x)*g(x)) directly in terms of integral(f) and integral(g)
  2. a composition rule for integral(f(g(x))) directly in terms of integral(f) and integral(g)
  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号