
Public Member Functions | |
| Expr (String s) throws Error | |
| Construct a mathematical expression containing numbers only. | |
| Expr (String s, List< StkOp > f, StkOpRepository funcRep) throws Error | |
| Construct a function from the specified string and variables. | |
| String | getString () |
| Gets the expression as a string. | |
| String | getProgramListString () |
| Gets the "program" as a printable string. | |
| double | eval () |
| Evaluate the expression. | |
| boolean | isConstant () |
Returns true if the expression is determined to be a constant. | |
| boolean | dependsOn (StkOp f) |
Returns true if the expression contains the specified function. | |
| boolean | dependsOnVariables () |
Returns true if the expression uses external variables. | |
| void | replaceVar (String name, StkVar var) |
| Replaces all occurances of a variable with another one in the program. | |
| void | evalStack (StkPointer sp0) |
| Evaluates the stack. | |
| StkOp[] | getInternalProgram () |
| Gets the "program". | |
| String | getClassName () |
| Gets the class name. | |
Static Public Member Functions | |
| static int | findExprEnd (String str, int i) |
| Finds end of subexpression starting at the specified character. | |
Classes | |
| class | Error |
| Exception thrown by the Expr constructor in case of syntax error. | |
Example:
f(x) = x^0.5*atan(1)/sqrt(pi)
<blockquote>
StkOp vX = new StkVar("x"); // define variable
List<StkOp> funcs = new ArrayList<StkOp>();
funcs.add(vX);
funcs.add(new StkConst("pi", Math.PI)); // define a constant
try {
Expr expr = new Expr("x^0.5*atan(1)/sqrt(pi)", funcs); // create Expr
vX.value = 5; // set value of variable
System.out.println("f(5) = " + expr.eval()); // calculate f(5)
} catch(Expr.Error ex) {
ex.printStackTrace();
}
</blockquote>
| gridripper::math::expr::Expr::Expr | ( | String | s | ) | throws Error [inline] |
Construct a mathematical expression containing numbers only.
| s | the expression |
| gridripper::math::expr::Expr::Expr | ( | String | s, | |
| List< StkOp > | f, | |||
| StkOpRepository | funcRep | |||
| ) | throws Error [inline] |
Construct a function from the specified string and variables.
| s | the expression | |
| f | extra functions and variables | |
| funcRep | function repository |
| String gridripper::math::expr::Expr::getString | ( | ) | [inline] |
Gets the expression as a string.
| String gridripper::math::expr::Expr::getProgramListString | ( | ) | [inline] |
Gets the "program" as a printable string.
Useful for debugging.
| double gridripper::math::expr::Expr::eval | ( | ) | [inline] |
Evaluate the expression.
| boolean gridripper::math::expr::Expr::dependsOn | ( | StkOp | f | ) | [inline, virtual] |
Returns true if the expression contains the specified function.
Subexpressions are also checked, recursively.
Reimplemented from gridripper::math::expr::StkFunc.
| boolean gridripper::math::expr::Expr::dependsOnVariables | ( | ) | [inline] |
Returns true if the expression uses external variables.
| void gridripper::math::expr::Expr::replaceVar | ( | String | name, | |
| StkVar | var | |||
| ) | [inline] |
Replaces all occurances of a variable with another one in the program.
| name | the variable name | |
| var | the new variable |
| void gridripper::math::expr::Expr::evalStack | ( | StkPointer | sp0 | ) | [inline, virtual] |
| StkOp [] gridripper::math::expr::Expr::getInternalProgram | ( | ) | [inline] |
Gets the "program".
| String gridripper::math::expr::Expr::getClassName | ( | ) | [inline, virtual] |
1.5.6