Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the single unknown in an equation

I need a library to be able to parse an equation an give me the result giving the inputs.

For example something like this:

String equation = "5 = 6 / z"; 

EquationSolver solver = new EquationSolver(equation); 

double result = solver.getResult(); 

System.out.println("result: " + result);

And evaluates to: 6/5

Is there any kind of library for java that can do that for me? Basically I need the program to isolate the single unknown variable in an arbitrary equation...

Thanks Thomas

like image 548
evildrsauss Avatar asked Jun 24 '11 06:06

evildrsauss


People also ask

How do you find an unknown value?

In calculating a proportion, we need to identify the ratio with the known values and the ratio with one known and one unknown value, making sure the comparative values are in the same places in the ratio. We then use cross multiplication to solve for the unknown.

How do you find a single variable?

The linear equations in one variable is an equation which is expressed in the form of ax+b = 0, where a and b are two integers, and x is a variable and has only one solution. For example, 2x+3=8 is a linear equation having a single variable in it.


2 Answers

What you're looking for is a computer algebra system.

Wikipedia lists some options. I would check out Java Algebra System

like image 195
wjin Avatar answered Oct 11 '22 03:10

wjin


You need a Java expression Library for this. I found MVEL to be a good Java Expression Library

You can check this link for other java expression libraries. http://java-source.net/open-source/expression-languages

like image 43
ravia Avatar answered Oct 11 '22 01:10

ravia