| java.lang.Object edu.hws.jcm.functions.FunctionParserExtension edu.hws.jcm.functions.TableFunction
TableFunction | public class TableFunction extends FunctionParserExtension (Code) | | A TableFunction is a function that is specified by a table of (x,y)-points.
Values are interpolated between the specified x-values. 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 x-values of the defining points.
|
Field Summary | |
final public 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 x-values between the points that define the function. | final public 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 x-values between the points that define the function. | final public 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. | final public 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. | final public 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. |
Constructor Summary | |
public | TableFunction() Create a TableFunction with SMOOTH style and no points. | public | TableFunction(int sytle) Create a TableFunction with specified style and no points.
Parameters: style - The style for the function: SMOOTH, PIECEWISE_LINEAR, STEP,STEP_LEFT, or STEP_RIGHT. |
Method Summary | |
public void | addIntervals(int intervals, double xmin, double xmax) Add points to the table. | public int | addPoint(double x, double y) Add a point with the specified x and y coordinates. | public void | addPoints(double[] xCoords, double[] yCoords) Add points to the table. | public void | apply(StackOfDouble stack, Cases cases) Override method apply() from interface FunctionParserExtension, to handle cases properly. | public void | copyDataFrom(TableFunction source) Copy data from another TableFunction, except that the name of the funcion is
not duplicated. | public boolean | dependsOn(Variable wrt) Returns false. | public Function | derivative(int wrt) Compute the derivative of this function. | public Function | derivative(Variable wrt) Returns null.
It really should be the constant function zero, but I don't expect this ever to be
called. | public int | findPoint(double x) If there is a point in the list with x-coordinate x, then this function returns
the index of that point in the list (where the index of the first point is zero). | public int | getArity() Returns the arity of the function, which is 1. | public int | getPointCount() Gets the number of points in the table. | public int | getStyle() Get the style of this TableFunction, which specifies how values are
interpolated between points on the curve.
The style of this TableFunction. | public double | getVal(double x) Get the value of the function at x, using interpolation if x lies between
two x-coordinates in the list of points that define the function. | public double | getVal(double[] params) Get the value of the function at the specified parameter value. | public double | getValueWithCases(double[] params, Cases cases) Get the value of the function at the specified parameter value. | public double | getX(int i) Get the x-coordinate in the i-th point, where the first point
is number zero. | public double | getY(int i) Get the y-coordinate in the i-th point, where the first point
is number zero. | public void | removeAllPoints() Remove all points. | public void | removePointAt(int i) Removes the i-th point from the list of points. | public void | setStyle(int style) Set the style of this TableFunction, to specify how values are interpolated
between points on the curve.
Parameters: style - One of the style constants SMOOTH, PIECEWISE_LINEAR, STEP,STEP_LEFT, STEP_RIGHT. | public void | setY(int i, double y) Set the y-coordinate in the i-th point to y, where the first point
is number zero. |
PIECEWISE_LINEAR | final public static int PIECEWISE_LINEAR(Code) | | If the style of the function is set to PIECEWISE_LINEAR,
then linear interpolation is used to find the value
of the functions for x-values between the points that define the function.
|
SMOOTH | final public static int SMOOTH(Code) | | If the style of the function is set to SMOOTH,
then cubic interpolation is used to find the value
of the functions for x-values between the points that define the function.
|
STEP | final public static int STEP(Code) | | 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.
|
STEP_LEFT | final public static int STEP_LEFT(Code) | | 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.
|
STEP_RIGHT | final public static int STEP_RIGHT(Code) | | 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.
|
TableFunction | public TableFunction()(Code) | | Create a TableFunction with SMOOTH style and no points.
|
TableFunction | public TableFunction(int sytle)(Code) | | Create a TableFunction with specified style and no points.
Parameters: style - The style for the function: SMOOTH, PIECEWISE_LINEAR, STEP,STEP_LEFT, or STEP_RIGHT. |
addIntervals | public void addIntervals(int intervals, double xmin, double xmax)(Code) | | Add points to the table. The number of points added is intervals + 1.
The x-coordinates are evenly spaced between xmin and xmax. The y-coordinates
are zero.
Parameters: 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. Parameters: xmin - The minimim x-coordinate for added points. Parameters: xmax - The maximum x-coodinate for added points. Should be greater thanxmin, for efficiency, but no error occurs if it is not. |
addPoint | public int addPoint(double x, double y)(Code) | | Add a point with the specified x and y coordinates. If a point with the
given x coordinate already exists in the table, then no new point is added,
but the associated y-value is changed.
(If x is Double.NaN, then no change is made and the return value is -1.)
Parameters: x - The x-coordinate of the point to be added or modified. Parameters: y - The y-coordinate of the point. the position of the point in the list of points, where the first point is at position zero. |
addPoints | public void addPoints(double[] xCoords, double[] yCoords)(Code) | | Add points to the table. The x-coordinates of the points are taken from
the xCoords array. The y-coordinate for the i-th point is yCoords[i], if
an i-th position exists in this array. Otherwise, the y-coordinate is
is zero. (Note that if xCoords[i] duplicates an x-value already in
the table, then no new point is added but the corresponging y-value is changed.)
Parameters: xCoords - A list of x-coordinates to be added to the table. If this isnull, then nothing is done. Parameters: yCoords - The value of yCoords[i], if it exists, is the y-coordinatecorresponding to xCoords[i]. Otherwise, the y-coordinate is undefined.This can be null, in which case all y-coordinates are zero. |
apply | public void apply(StackOfDouble stack, Cases cases)(Code) | | Override method apply() from interface FunctionParserExtension, to handle cases properly.
Not meant to be called directly.
|
copyDataFrom | public void copyDataFrom(TableFunction source)(Code) | | Copy data from another TableFunction, except that the name of the funcion is
not duplicated. The new TableFunction is nameless.
|
derivative | public Function derivative(int wrt)(Code) | | Compute the derivative of this function. The value of the parameter, wrt, must be 1 or an
IllegalArguemntException will be thrown.
|
derivative | public Function derivative(Variable wrt)(Code) | | Returns null.
It really should be the constant function zero, but I don't expect this ever to be
called. Since dependsOn(wrt) returns false, it will never be called within the JCM system.
|
findPoint | public int findPoint(double x)(Code) | | If there is a point in the list with x-coordinate x, then this function returns
the index of that point in the list (where the index of the first point is zero).
If there is no such point, then -1 is returned.
|
getArity | public int getArity()(Code) | | Returns the arity of the function, which is 1.
|
getPointCount | public int getPointCount()(Code) | | Gets the number of points in the table.
|
getStyle | public int getStyle()(Code) | | Get the style of this TableFunction, which specifies how values are
interpolated between points on the curve.
The style of this TableFunction. This is one of the constantsSMOOTH, PIECEWISE_LINEAR, STEP, STEP_LEFT, or STEP_RIGHT. |
getVal | public double getVal(double x)(Code) | | Get the value of the function at x, using interpolation if x lies between
two x-coordinates in the list of points that define the function. If x is
outside the range of x-coords in the table, the value of the function is Double.NaN.
|
getVal | public double getVal(double[] params)(Code) | | Get the value of the function at the specified parameter value.
|
getValueWithCases | public double getValueWithCases(double[] params, Cases cases)(Code) | | Get the value of the function at the specified parameter value.
|
getX | public double getX(int i)(Code) | | Get the x-coordinate in the i-th point, where the first point
is number zero. Throws an IllegalArgumentException if i is
less than zero or greater than or equal to the number of points.
|
getY | public double getY(int i)(Code) | | Get the y-coordinate in the i-th point, where the first point
is number zero. Throws an IllegalArgumentException if i is
less than zero or greater than or equal to the number of points.
|
removeAllPoints | public void removeAllPoints()(Code) | | Remove all points. The resulting function is undefined everywhere.
|
removePointAt | public void removePointAt(int i)(Code) | | Removes the i-th point from the list of points. Throws an IllegalArgumentException if i is
less than zero or greater than or equal to the number of points.
|
setStyle | public void setStyle(int style)(Code) | | Set the style of this TableFunction, to specify how values are interpolated
between points on the curve.
Parameters: style - One of the style constants SMOOTH, PIECEWISE_LINEAR, STEP,STEP_LEFT, STEP_RIGHT. Other values are ignored. |
setY | public void setY(int i, double y)(Code) | | Set the y-coordinate in the i-th point to y, where the first point
is number zero. Throws an IllegalArgumentException if i is
less than zero or greater than or equal to the number of points.
|
|
|