jhplot.math.exp4j
Class PostfixExpression

java.lang.Object
  extended by jhplot.math.exp4j.PostfixExpression
All Implemented Interfaces:
Calculable

public final class PostfixExpression
extends Object
implements Calculable

Class for calculating values from a RPN postfix expression.
The default way to create a new instance of PostfixExpression is by using the static factory method fromInfix()


Method Summary
 double calculate(double... values)
          calculate the result of the expression and substitute the variables by their values beforehand
 double eval()
          delegate the calculation of a simple expression without variables
 double[] eval(String variableName, double[] a)
          Calculate values for array
 P1D eval(String variableName, double min, double max, int points)
          Calcalate P1D in the range.
 P1D eval(String variableName, P0D a)
          Calculate values for array
static PostfixExpression fromInfix(String expression)
          Deprecated. please use ExpressionBuilder API
static PostfixExpression fromInfix(String expression, Set<CustomFunction> customFunctions)
          Deprecated. please use ExpressionBuilder
 String getExpression()
          get the mathematical expression String
 NumberFormat getNumberFormat()
          get the used NumberFormat
 void setVariable(String name, double value)
          set a variable value for the calculation
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jhplot.math.exp4j.Calculable
getExpression
 

Method Detail

fromInfix

@Deprecated
public static PostfixExpression fromInfix(String expression)
                                   throws UnparsableExpressionException,
                                          UnknownFunctionException
Deprecated. please use ExpressionBuilder API

Factory method for creating PostfixExpressions from human readable infix expressions

Parameters:
expression - the infix expression to be used
Returns:
an equivalent PostfixExpression
Throws:
UnparsableExpressionException - if the expression was invalid
UnknownFunctionException - if an unknown function has been used

fromInfix

@Deprecated
public static PostfixExpression fromInfix(String expression,
                                                     Set<CustomFunction> customFunctions)
                                   throws UnparsableExpressionException,
                                          UnknownFunctionException
Deprecated. please use ExpressionBuilder

Factory method for creating PostfixExpressions from human readable infix expressions

Parameters:
expression - the infix expression to be used
customFunctions - the CustomFunction implementations used
Returns:
an equivalent PostfixExpression
Throws:
UnparsableExpressionException - if the expression was invalid
UnknownFunctionException - if an unknown function has been used

eval

public double eval()
delegate the calculation of a simple expression without variables

Specified by:
eval in interface Calculable
Returns:
the result

calculate

public double calculate(double... values)
                 throws IllegalArgumentException
calculate the result of the expression and substitute the variables by their values beforehand

Parameters:
values - the variable values to be substituted
Returns:
the result of the calculation
Throws:
IllegalArgumentException - if the variables are invalid

setVariable

public void setVariable(String name,
                        double value)
Description copied from interface: Calculable
set a variable value for the calculation

Specified by:
setVariable in interface Calculable
Parameters:
name - the variable name
value - the value of the variable

eval

public double[] eval(String variableName,
                     double[] a)
Calculate values for array

Parameters:
a - array with X values
Returns:

eval

public P1D eval(String variableName,
                P0D a)
Calculate values for array

Parameters:
a - array with X values
Returns:
P1D which keeps X and Y

eval

public P1D eval(String variableName,
                double min,
                double max,
                int points)
Calcalate P1D in the range.

Parameters:
variableName -
min - min value in X
max - max value in Y
points - number of points for evaluation
Returns:
P1D with the output

getExpression

public String getExpression()
get the mathematical expression String

Returns:
the expression

getNumberFormat

public NumberFormat getNumberFormat()
get the used NumberFormat

Returns:
the used NumberFormat


jHepWork 3.2 ©