An easy-to-use, real-valued mathematical expression interpreter
Mathematical expression interpreter for real-valued input.
Works only with real numbers and returns real numbers. Uses the Shunting
Yard Algorithm.
Have the mathematical expression you want to solve stored in a string in infix notation
e.g.
std::string expr = "-12.4 + exp(sin(rad(68))) * log10(96)";
Create a MathInterpreter
object and call init_with_expr()
initialize the interpreter with the given input expression.
e.g.
MathInterpreter inter;
inter.init_with_expr(expr);
Call calculate()
to calculate the expression and save it in a double.
e.g.
double result = inter.calculate();
Have the mathematical expression you want to solve stored in a string in infix notation. Use dollar sign($) before and after variable names to mark variables.
e.g.
std::string expr = "-12.4 + exp(sin(rad($x$))) * log10($y$)"; //x and y are variables.
Create a MathInterpreter
object and call init_with_expr()
initialize the interpreter with the given input expression.
e.g.
MathInterpreter inter;
inter.init_with_expr(expr);
Use set_value()
to set values for each registered variable.
e.g.
inter.set_value("x", 12.75);
inter.set_value("y", 3.12);
Call calculate()
to calculate the expression and save it in a double.
e.g.
double result = inter.calculate();
sin(2*$pi$*5) or sin(2*$PI$*5)