How can you solve equations in PHP?

耗尽温柔 提交于 2019-12-23 17:37:41

问题


I'm looking for a generalized equation solver in PHP. This could either be in the form of in-built functionality, a library, or even integration with another language if it comes to it. I am even comfortable with a joint solution that involves some combination of the above. I need this for an educational website on which I am working.

Let me give a series of equations that I would ideally expect such a solver to deal with:

x+5=8 => x=3
x^2=5 => x=+/-sqrt(5) [exact solution in terms of sqrt, ln, or whatever] AND
         x=+/-2.236 [approximate solution to certain number of digits]
x+y=-3 [solve in terms of y] => y=-x-3
x^2=-5 => x=+/5i
x+y=3 and x-y=3 => x=3, y=0

I hope this is not a bridge too far. If so, I'll build the functionality as each problem comes in-house, but if anyone knows of the proper library for such a set of problems, I would greatly appreciate it.


回答1:


Check out Sage, from their website:

Sage is a free open-source mathematics software system licensed under the GPL. It combines the power of many existing open-source packages into a common Python-based interface. Mission: Creating a viable free open source alternative to Magma, Maple, Mathematica and Matlab.

Sage has an AJAX-based notebook interface, that is probably as good as an API that you can use from PHP.




回答2:


First: your math solutions are wrong.

  • x+5=8 evaluates to x=3
  • x+y=-3, y evaluates to -x-3

etc.

To do the math: make an API call to Wolfram|Alpha.

Seeing as this is an educational venture, I would highly suggest that you do not create your own product and rely on third-party software. I would personally go with Wolfram Mathematica, and probably their pre-college solutions or go with Web Mathematica for web interfaces.

Note about Web Mathematica: it uses JSP or Java Servlets for it's back-end technology. More about specific technical details for Web Mathematica will be helpful.



来源:https://stackoverflow.com/questions/7621171/how-can-you-solve-equations-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!