Maths
Class MathsParse
java.lang.Object
Maths.MathsParse
public class MathsParse
- extends java.lang.Object
Class used to parse an equation represented by a string and return the result.
Variables are represented by a letter followed by any number of alphanumeric
characters. Multiply (represented by "*" should be stated explicitly, e.g.
a * b NOT a b or ab (the later of which would be parsed as a single variable).
Functions should be represented by "f[a,b,...]" where f is the function name
and a,b etc. are inputs. Inputs cannot contain other functions but can otherwise
contain an expression. The following functions are defined by default:
- ln[a] - The natural logarithm
- g[a,b,c] - The rate modifier of the bth class of c classes using a gamma
distribution with alpha value of a as per Yang 1993.
Additional functions can be defined by passing instances of classes that
implement FunctionParser
to the constructor.
- Version:
- 1.0
Method Summary |
double |
parseEquation(java.lang.String equation,
java.util.Map<java.lang.String,java.lang.Double> values)
Parses an equation and returns the result |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MathsParse
public MathsParse(FunctionParser... fps)
- Default constructor.
- Parameters:
fps
- A variable number of parsers that define additional functions.
If none is passed then only the default functions are avaliable.
parseEquation
public double parseEquation(java.lang.String equation,
java.util.Map<java.lang.String,java.lang.Double> values)
throws NoSuchFunction,
WrongNumberOfVariables
- Parses an equation and returns the result
- Parameters:
equation
- The equation to parsevalues
- Map from a string to a double that represents the value of
any variables in the equation
- Returns:
- The result of the equation
- Throws:
NoSuchFunction
- If the equation uses an undefined function
WrongNumberOfVariables
- If the equation uses a function and passes
it the wrong number of variables