

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: INNER  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object  +edu.hws.jcm.functions.FunctionParserExtension  +edu.hws.jcm.functions.TableFunction
A TableFunction is a function that is specified by a table of (x,y)points. Values are interpolated between the specified xvalues. This can be done in several differnt ways; the method that is used is controlled by the "Style" property. Since a TableFunction extends FunctionParserExtension, a TableFunction can be added to a Parser (provided it has a name), and it can then be used in expressions parsed by that parser. Note that this class is meant to be used for functions that are defined by a fairly small number of points, since each function evaluation involves a linear search through the list of xvalues of the defining points.
Field Summary  
static int 
PIECEWISE_LINEAR
If the style of the function is set to PIECEWISE_LINEAR, then linear interpolation is used to find the value of the functions for xvalues between the points that define the function. 
static int 
SMOOTH
If the style of the function is set to SMOOTH, then cubic interpolation is used to find the value of the functions for xvalues between the points that define the function. 
static int 
STEP
If the style of the function is set to STEP, then the function is piecewise constant, and the value of the function at x is taken from the nearest point in the list of points that define the function. 
static int 
STEP_LEFT
If the style of the function is set to STEP_LEFT, then the function is piecewise constant, and the value of the function at x is taken from the nearest point to the left in the list of points that define the function. 
static int 
STEP_RIGHT
If the style of the function is set to STEP_RIGHT, then the function is piecewise constant, and the value of the function at x is taken from the nearest point to the right in the list of points that define the function. 
Fields inherited from class edu.hws.jcm.functions.FunctionParserExtension 
name 
Constructor Summary  
TableFunction()
Create a TableFunction with SMOOTH style and no points. 

TableFunction(int sytle)
Create a TableFunction with specified style and no points. 
Method Summary  
void 
addIntervals(int intervals,
double xmin,
double xmax)
Add points to the table. 
int 
addPoint(double x,
double y)
Add a point with the specified x and y coordinates. 
void 
addPoints(double[] xCoords,
double[] yCoords)
Add points to the table. 
void 
apply(StackOfDouble stack,
Cases cases)
Override method apply() from interface FunctionParserExtension, to handle cases properly. 
void 
copyDataFrom(TableFunction source)
Copy data from another TableFunction, except that the name of the funcion is not duplicated. 
boolean 
dependsOn(Variable wrt)
Returns false. 
Function 
derivative(int wrt)
Compute the derivative of this function. 
Function 
derivative(Variable wrt)
Returns null. 
int 
findPoint(double x)
If there is a point in the list with xcoordinate x, then this function returns the index of that point in the list (where the index of the first point is zero). 
int 
getArity()
Returns the arity of the function, which is 1. 
int 
getPointCount()
Gets the number of points in the table. 
int 
getStyle()
Get the style of this TableFunction, which specifies how values are interpolated between points on the curve. 
double 
getVal(double x)
Get the value of the function at x, using interpolation if x lies between two xcoordinates in the list of points that define the function. 
double 
getVal(double[] params)
Get the value of the function at the specified parameter value. 
double 
getValueWithCases(double[] params,
Cases cases)
Get the value of the function at the specified parameter value. 
double 
getX(int i)
Get the xcoordinate in the ith point, where the first point is number zero. 
double 
getY(int i)
Get the ycoordinate in the ith point, where the first point is number zero. 
void 
removeAllPoints()
Remove all points. 
void 
removePointAt(int i)
Removes the ith point from the list of points. 
void 
setStyle(int style)
Set the style of this TableFunction, to specify how values are interpolated between points on the curve. 
void 
setY(int i,
double y)
Set the ycoordinate in the ith point to y, where the first point is number zero. 
Methods inherited from class edu.hws.jcm.functions.FunctionParserExtension 
appendOutputString, compileDerivative, doParse, extent, getName, setName, setParensCanBeOptional 
Methods inherited from class java.lang.Object 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Field Detail 
public static final int SMOOTH
public static final int PIECEWISE_LINEAR
public static final int STEP
public static final int STEP_LEFT
public static final int STEP_RIGHT
Constructor Detail 
public TableFunction()
public TableFunction(int sytle)
style
 The style for the function: SMOOTH, PIECEWISE_LINEAR, STEP,
STEP_LEFT, or STEP_RIGHT.Method Detail 
public void copyDataFrom(TableFunction source)
public void setStyle(int style)
style
 One of the style constants SMOOTH, PIECEWISE_LINEAR, STEP,
STEP_LEFT, STEP_RIGHT. Other values are ignored.public int getStyle()
public void addPoints(double[] xCoords, double[] yCoords)
xCoords
 A list of xcoordinates to be added to the table. If this is
null, then nothing is done.yCoords
 The value of yCoords[i], if it exists, is the ycoordinate
corresponding to xCoords[i]. Otherwise, the ycoordinate is undefined.
This can be null, in which case all ycoordinates are zero.public void addIntervals(int intervals, double xmin, double xmax)
intervals
 The number of intervals. The number of points added is intervals + 1.
The value should be at least 1. If not, nothing is done.xmin
 The minimim xcoordinate for added points.xmax
 The maximum xcoodinate for added points. Should be greater than
xmin, for efficiency, but no error occurs if it is not.public int addPoint(double x, double y)
x
 The xcoordinate of the point to be added or modified.y
 The ycoordinate of the point.public int getPointCount()
public double getX(int i)
public double getY(int i)
public void setY(int i, double y)
public int findPoint(double x)
public void removePointAt(int i)
public void removeAllPoints()
public double getVal(double x)
public double getValueWithCases(double[] params, Cases cases)
public double getVal(double[] params)
public Function derivative(int wrt)
public Function derivative(Variable wrt)
public boolean dependsOn(Variable wrt)
public int getArity()
public void apply(StackOfDouble stack, Cases cases)
apply
in class FunctionParserExtension
edu.hws.jcm.data.ExpressionCommand
stack
 contains results of previous commands in the program.cases
 if nonnull, any case information generated during evaluation should be recorded here.


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: INNER  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 