opale.mathtools
Class ParseFunction

java.lang.Object
  |
  +--opale.mathtools.ScanString
        |
        +--opale.mathtools.ParseFunction

public class ParseFunction
extends ScanString

This class will parse a function definition and solve it returning the value. The function may have upto 3 independent variables in it (x,y,z).

Known Bugs This class is not fool proof. If the answer is wrong then use the parenthesis to force the order of evaluation. The most likely place this will be needed is in the use of the power command. The exponent is not evaluated correctly if it begins with a unary operator.

List of recognised commands

Version:
$Revision: 1.8 $, $Date: 1996/08/12 23:37:08 $

Field Summary
 boolean debug
          Debug variable.
 
Fields inherited from class opale.mathtools.ScanString
EOS, ERROR, NUMBER, nval, sval, UNKNOWN
 
Constructor Summary
ParseFunction()
          Instantiate the class
ParseFunction(java.lang.String s)
          Instantiate the class and define the string to parse.
 
Method Summary
 double getResult()
          Return the solution of the function if it has no independent values or they have already been set using the set methods
 double getResult(double x)
          Return the solution of the function given the independent values
 double getResult(double x, double y)
          Return the solution of the function given the independent values
 double getResult(double x, double y, double z)
          Return the solution of the function given the independent values
 double getResult(double t, double x, double y, double z)
          Return the solution of the function given the independent values
 double[] getResults(int n, double[] x)
          Return an array of solutions given an array of x values
 double[] getResults(int n, double[] x, double[] y)
          Return an array of solutions given an array of x values and y values
 double[] getResults(int n, double[] x, double[] y, double[] z)
          Return an array of solutions given an array of x values, y values and z values.
 double[] getResults(int n, double[] t, double[] x, double[] y, double[] z)
          Return an array of solutions given an array of x values, y values and z values and t values.
 boolean[] getVariables()
          Return a boolean array with index 0 true if the independent variable x was found in the function, index 1 true if y was found, and index 2 true if z was found, and index 3 true si t was found.
 boolean parse()
          Parse the previously set string
 boolean parse(java.lang.String s)
          Parse the string.
 void setDeg()
          Indicates that the argument of trigonometrics functions are measured in degrees.
 void setRad()
          Indicates that the argument of trigonometrics functions are in radians.
 void setT(double t)
          Set the value of the independent variable T.
 void setX(double x)
          Set the value of the independent variable X.
 void setY(double y)
          Set the value of the independent variable Y.
 void setZ(double z)
          Set the value of the independent variable Z.
 
Methods inherited from class opale.mathtools.ScanString
addKeyWord, getKeyValue, nextWord, resetKeyWords, setString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public boolean debug
Debug variable. If set true debug output is printed.
Constructor Detail

ParseFunction

public ParseFunction()
Instantiate the class

ParseFunction

public ParseFunction(java.lang.String s)
Instantiate the class and define the string to parse.
Parameters:
s - The string to be parsed.
Method Detail

parse

public boolean parse(java.lang.String s)
Parse the string.
Parameters:
s - The string to parse
Returns:
true if it was successful, false otherwise.

parse

public boolean parse()
Parse the previously set string
Returns:
true if it was successful, false otherwise.

getResult

public double getResult(double x,
                        double y,
                        double z)
                 throws java.lang.Exception
Return the solution of the function given the independent values
Parameters:
x - indpendent x value
y - indpendent y value
z - indpendent z value
Returns:
solution of the function

getResult

public double getResult(double t,
                        double x,
                        double y,
                        double z)
                 throws java.lang.Exception
Return the solution of the function given the independent values
Parameters:
t - indpendent t value
x - indpendent x value
y - indpendent y value
z - indpendent z value
Returns:
solution of the function

getResult

public double getResult(double x,
                        double y)
                 throws java.lang.Exception
Return the solution of the function given the independent values
Parameters:
x - indpendent x value
y - indpendent y value
Returns:
solution of the function

getResult

public double getResult(double x)
                 throws java.lang.Exception
Return the solution of the function given the independent values
Parameters:
x - indpendent x value
Returns:
solution of the function

getResult

public double getResult()
                 throws java.lang.Exception
Return the solution of the function if it has no independent values or they have already been set using the set methods
Returns:
solution of the function
See Also:
setX(double), setY(double), setZ(double)

getResults

public double[] getResults(int n,
                           double[] x)
                    throws java.lang.Exception
Return an array of solutions given an array of x values
Parameters:
n - number of values to process in the input array
x - Array containing the x values.
Returns:
Array containing the solutions.
Throws:
java.lang.Exception - Generic exception if the array index n<=0, or x is null.

getResults

public double[] getResults(int n,
                           double[] x,
                           double[] y)
                    throws java.lang.Exception
Return an array of solutions given an array of x values and y values
Parameters:
n - number of values to process in the input array
x - Array containing the x values.
y - Array containing the y values.
Returns:
Array containing the solutions.
Throws:
java.lang.Exception - Generic exception if the array index n<=0, or x is null, or y is null.

getResults

public double[] getResults(int n,
                           double[] x,
                           double[] y,
                           double[] z)
                    throws java.lang.Exception
Return an array of solutions given an array of x values, y values and z values.
Parameters:
n - number of values to process in the input array
x - Array containing the x values.
y - Array containing the y values.
Returns:
Array containing the solutions.
Throws:
java.lang.Exception - Generic exception if the array index n<=0, or x is null, or y is null, or z is null.

getResults

public double[] getResults(int n,
                           double[] t,
                           double[] x,
                           double[] y,
                           double[] z)
                    throws java.lang.Exception
Return an array of solutions given an array of x values, y values and z values and t values.
Parameters:
n - number of values to process in the input array
t - Array containing the t values.
x - Array containing the x values.
y - Array containing the y values.
z - Array containing the z values.
Returns:
Array containing the solutions.
Throws:
java.lang.Exception - Generic exception if the array index n<=0, or x is null, or y is null, or z is null.

getVariables

public boolean[] getVariables()
Return a boolean array with index 0 true if the independent variable x was found in the function, index 1 true if y was found, and index 2 true if z was found, and index 3 true si t was found.

setT

public void setT(double t)
Set the value of the independent variable T.

setX

public void setX(double x)
Set the value of the independent variable X.

setY

public void setY(double y)
Set the value of the independent variable Y.

setZ

public void setZ(double z)
Set the value of the independent variable Z.

setDeg

public void setDeg()
Indicates that the argument of trigonometrics functions are measured in degrees.

setRad

public void setRad()
Indicates that the argument of trigonometrics functions are in radians.