|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jwo.utils.expression.MathEvaluator
Evaluates a mathematical expression stored in an postfix stack
(created using MathParser
). Can handle basic arithmetic
and trig operators. +, -, *, /, ^, sin, cos, tan, sqrt, asin, acos,
atan, ln. Can handle constants pi and e. Can handle random number
generators rand (rectangular distribution between 0-1) and gauss
(normal disitribution with mean of 0 and variance of 1). Will
substitute variables z1,z2,x and y with numbers defined by the
constructor or the relevant evaluate() method.
Modified from original code described at
www.devx.com/premier/mgznarch/javapro/2001/05may01/ps0105/ps0105.asp.
Constructor Summary | |
MathEvaluator()
Creates an evaluator with all variables set to 0. |
|
MathEvaluator(double[] z)
Creates an evaluator with variables z0-z9 defined in the given array. |
Method Summary | |
double |
evaluate(Stack operations)
Evalutes the given expression stack using (if required), the stored variable substitutions. |
double |
evaluate(Stack operations,
double z1,
double z2,
double x,
double y)
Evalutes the given expression stack using (if required), the stored variable substitutions. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MathEvaluator()
public MathEvaluator(double[] z)
z
- List of variables for substitution. Expressions
that use variables should name them z0 - z9.Method Detail |
public double evaluate(Stack operations)
operations
- Expression stack containing postfixed expression.
public double evaluate(Stack operations, double z1, double z2, double x, double y)
operations
- Expression stack containing postfixed expression.z1
- Value of z1 to substitute.z2
- Value of z2 to substitute.x
- Value of x to substitute.y
- Value of y to substitute.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |