I would like to ask whether is there a library or method in java that can take a string which contains the prescription of a function like "4x^2 + 3x" and return the integrated version of the string. When the input is "4x^2 + 3x" I want to get an output like "(4/3)x^3 + (3/2)x^2 + c".
Asked
Active
Viewed 1,333 times
-2
-
3sometimes asking suggestion for a library considered as off-topic in stackoverflow. – Razib May 17 '15 at 17:17
-
1@Razib not sometimes, it is always off-topic. – Pshemo May 17 '15 at 17:31
-
Symja is written in Java. Try the online demo: http://symjaweb.appspot.com/ >>> Integrate(4*x^2 + 3*x, x) 3/2*x^2+4/3*x^3 >>> NIntegrate(4*x^2 + 3*x, {x,-3,3}) 71.99999999999996 – axelclk May 18 '15 at 07:00
3 Answers
2
You could use the following java Polynomial class http://www.comscigate.com/cs/IntroSedgewick/90scientific/92symbolic/Polynomial.java.html. It has a public Polynomial integrate()
function.
You would have to parse your String into an instance of this class.

WilliamSF
- 284
- 1
- 8
-
I wonder if the OP needs to integrate anything, including functions like sin, cos or log? – Ron Kuper May 17 '15 at 17:23
1
It is better to use Matlab for this. It has all the features you can think about in Mathematics. it also allows you to plot your results and use the graphs in servlets.
- Install the MATLAB runtime and generated JARs
- Write your functions in Matlab
- Generate a JAR containing them from Matlab
- Call them in your custom Java classes
Check out an example of integrals and learn more about how to setup the development environment
0
What you are asking for is generally known as "symbolic math". You can do this sort of thing online at Wolfram Alpha (probably other places, too):
Type in "derivative of 4x^2 + 3x" or "integral of 4x^2 + 3x" to see...

Ron Kuper
- 817
- 5
- 14