Is it possible, to resolve mathematical functions dynamically, e.g by the use of a given API?
Given there is a function
a = b + c
is there a way to write something comparable to:
Function func = new Function("a=b+c");
Result result = func.resolve("a=1", "b=?", "c=a");
System.out.println(result.getValue());
Ideally, resolve(Object... args)
should accept further classes of type Function
.
EDIT 1: The API should be includable into a Java EE environment such as jBossAS.
EDIT 2: Actually I want to solve equations with one unknown variable, but I want to avoid hard coded functions. Thus, for the function
a+b=c
I don't want to write the functions hard coded
getA(int b, int c){...}
getB(int a, int c){...}
getC(int a, int b){...}
Instead, as @Berylium says, I want to evaluate the expression dynamically.
EDIT 3: I'm trying symja right now and I think I'm getting closer, but I have troubles with the syntax.
try {
F.initSymbols(null);
EvalUtilities util = new EvalUtilities();
StringBufferWriter buf = new StringBufferWriter();
String input = "....";
IExpr result = util.evaluate(input);
OutputFormFactory.get().convert(buf, result);
String output = buf.toString();
System.out.println("Evaluation for " + input + " is " + output);
} catch (final Exception e) {
Can you help me with the input syntax?
EDIT 4: Got it :-) For input
String input = "Solve[{a==10,c==20,a+b==c},{a,b,c}]";
the output is
Evaluation for Solve[{a==10,c==20,a+b==c},{a,b,c}] is {{a->10,c->20,b->10}}
After adding symja JAR to the build path, the following code prints the output below:
Code:
Output: