I don't know much about DDMathParser
(OK, I don't know anything about it), but taking a look at the documentation gives some clues about what is going wrong with your code.
Based on the documentation, I could find not example of where DDMathParser
could handle symbolic expressions. All of the examples on the Usage page show numeric expressions.
For symbolic math, see Symbolic Math Library in C/C++/Obj-C .
In addition, it looks like you are trying to solve for two variables with a single equation, which is certainly not going to result in a numeric solution.
However, if you are just trying to substitute values in for x
and y
, you should use the $
sign before them as the documentation says:
If you don't know what the value of a particular term should be when
the string is constructed, that's ok; simply use a variable:
NSString *math = @"6 * $a";
So if you just want to substitute values in your expression, try using:
string expression = @"(2+$x)6+2*$x+2*$y";
Then fill in with values.
NSDictionary *s = @{@"x" : 42, @"y" : 43};
And evaluate.
DDMathEvaluator *eval = [DDMathEvaluator sharedMathEvaluator];
NSLog(@"%@", [eval evaluateString:expression withSubstitutions:s]);