public class LinearSpline1d extends Diff1Function1x1Base implements java.lang.Iterable<LinearSpline1d.Knot>
Modifier and Type | Class and Description |
---|---|
static class |
LinearSpline1d.Knot |
Constructor and Description |
---|
LinearSpline1d()
Creates a empty spline
|
LinearSpline1d(double[] x,
double[] y)
Creates a spline from specified values of x and y at each knot point.
|
LinearSpline1d(LinearSpline1d spline)
Creates a spline from a copy of an existing one.
|
Modifier and Type | Method and Description |
---|---|
LinearSpline1d.Knot |
addKnot(double x,
double y)
Adds another knot point to this spline at a specified x coordinate.
|
void |
clearKnots()
Removes all knots from from this spline.
|
LinearSpline1d |
clone() |
LinearSpline1d |
copy()
Creates a copy of this spline.
|
boolean |
equals(LinearSpline1d spline)
Queries whether this spline is equal to another spline.
|
double |
eval(double x)
Evaluates the y value of this spline for a specific x value.
|
double |
eval(DoubleHolder deriv,
double x)
Evaluates both the value and first derivative of this function at a
specified input value.
|
double |
eval(double x,
IntHolder lastIdx)
Evaluates the y value of this spline for a specific x value.
|
double |
evalDeriv(double x)
Evaluates first derivative of this function at a
specified input value.
|
double |
evalDy(double x)
Evaluates the derivative (with respect to x) of this spline for a
specific x value.
|
double |
evalDy(double x,
IntHolder lastIdx)
Evaluates the derivative (with respect to the parameter) of this spline
for a specific x value.
|
LinearSpline1d.Knot |
getFirstKnot()
Returns the first knot in this spline, or
null if there
are no knots. |
LinearSpline1d.Knot |
getKnot(int idx)
Returns the
idx -th knot in this spline. |
LinearSpline1d.Knot |
getLastKnot()
Returns the last knot in this spline, or
null if there
are no knots. |
LinearSpline1d.Knot |
getNextKnot(double x)
Find the knot immediately following x.
|
LinearSpline1d.Knot |
getPreceedingKnot(double x)
Find the knot immediately preceeding x.
|
LinearSpline1d.Knot |
getPreceedingKnot(double x,
IntHolder lastIdx)
Find the knot immediately preceeding x.
|
double |
getX0()
Returns the firxt x value of this spline.
|
double |
getXLast()
Returns the last x value of this spline.
|
double[] |
getXValues()
Returns an array giving the values of x at each knot.
|
boolean |
isWritable()
Returns
true if this component should in fact be written to
secondary storage. |
java.util.Iterator<LinearSpline1d.Knot> |
iterator()
Returns an iterator for the knots in this spline.
|
int |
numKnots()
Returns the number of knots in this spline.
|
boolean |
removeKnot(LinearSpline1d.Knot knot)
Removes a knot from this spline.
|
void |
scan(ReaderTokenizer rtok,
java.lang.Object ref)
Scans this spline from a ReaderTokenizer.
|
void |
set(double[] x,
double[] y)
Sets this spline from specified values of x and y at each knot point.
|
void |
set(LinearSpline1d spline)
Sets this spline to be a copy of another spline.
|
void |
write(java.io.PrintWriter pw,
NumberFormat fmt,
java.lang.Object ref)
Writes a text description of this spline to a PrintWriter.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
eval, evalDeriv
eval, inputSize
public LinearSpline1d()
public LinearSpline1d(double[] x, double[] y)
x
- x values at each knot pointy
- y values at each knot pointpublic LinearSpline1d(LinearSpline1d spline)
spline
- spline to copypublic void set(double[] x, double[] y)
x
- x values at each knot pointy
- y values at each knot pointpublic double[] getXValues()
public LinearSpline1d.Knot addKnot(double x, double y)
x
- x value at the knoty
- y value at the knotpublic boolean removeKnot(LinearSpline1d.Knot knot)
knot
- knot to removepublic void clearKnots()
public LinearSpline1d.Knot getPreceedingKnot(double x)
knot.getX0() <= x
. If no such knot exists, null
is returned.x
- value for which preceeding knot is soughtpublic LinearSpline1d.Knot getPreceedingKnot(double x, IntHolder lastIdx)
knot.getX0() <= x
. If no such knot exists, null
is returned.
The optional parameter lastIdx
, described below, can be used
to significantly reduce the search speed when queries are made with
increasing values of x.
x
- value for which preceeding knot is soughtlastIdx
- if non-null, specifies a index value giving a hint on
where to start the knot search. On output, this value is set to the index
of the returned knot, or -1 if no knot is found.public LinearSpline1d.Knot getNextKnot(double x)
knot.x0 > x
. If no such knot exists, null
is returned.x
- value for which next knot is soughtpublic double eval(double x)
eval
in interface Function1x1
eval
in class Diff1Function1x1Base
x
- value at which the y value should be computedpublic double eval(double x, IntHolder lastIdx)
The optional parameter lastIdx
, described below, can be used
to significantly reduce the search speed when queries are made with
increasing values of x.
x
- value at which the y value should be computedlastIdx
- if non-null, specifies a index value giving a hint on
where to search for the knot preceeding x. On output, this value is set
to the index of the preceeding knot, or -1 if no preceeding knot is
found.public double evalDy(double x)
x
- value at which the derivative should be computedpublic double eval(DoubleHolder deriv, double x)
Diff1Function1x1Base
eval
in interface Diff1Function1x1
eval
in class Diff1Function1x1Base
deriv
- if non-null, returns the derivative valuex
- input valuepublic double evalDeriv(double x)
Diff1Function1x1
evalDeriv
in interface Diff1Function1x1
x
- input valuepublic double evalDy(double x, IntHolder lastIdx)
The optional parameter lastIdx
, described below, can be used
to significantly reduce the search speed when queries are made with
increasing values of x.
x
- value for which the derivative should be computedlastIdx
- if non-null, specifies a index value giving a hint on
where to search for the knot preceeding x. On output, this value is set
to the index of the preceeding knot, or -1 if no preceeding knot is
found.public void scan(ReaderTokenizer rtok, java.lang.Object ref) throws java.io.IOException
2 n
numeric values giving
the x and y values for each of the n
knots, and terminated
with a closing square bracket. Whitespace characters are ignored. For
example,
[ 0.0 1.0 2.0 4.3 3.0 5.0 ]describes a spline with three knots, with x and y equal to (0, 1), (2, 4.4), and (3, 5), respectively.
scan
in interface Scannable
scan
in class Diff1Function1x1Base
rtok
- Tokenizer from which to scan the splineref
- optional reference object (not used)java.io.IOException
- if an I/O or formatting error occuredpublic void write(java.io.PrintWriter pw, NumberFormat fmt, java.lang.Object ref) throws java.io.IOException
scan
.write
in interface Scannable
write
in class Diff1Function1x1Base
pw
- writer to which the spline should be writtenfmt
- describes how the numbers should be formattedref
- optional reference object (not used)java.io.IOException
- if an I/O error occuredpublic boolean isWritable()
true
if this component should in fact be written to
secondary storage. This gives subclasses control over whether or
not they are actually written out.isWritable
in interface Scannable
isWritable
in class Diff1Function1x1Base
true
if this component should be written to
secondary storage.public int numKnots()
public LinearSpline1d.Knot getKnot(int idx)
idx
-th knot in this spline.idx
- index of the requested knotidx
-th knotpublic LinearSpline1d.Knot getFirstKnot()
null
if there
are no knots.public LinearSpline1d.Knot getLastKnot()
null
if there
are no knots.public double getX0()
public double getXLast()
public java.util.Iterator<LinearSpline1d.Knot> iterator()
iterator
in interface java.lang.Iterable<LinearSpline1d.Knot>
public void set(LinearSpline1d spline)
spline
- spline to copypublic LinearSpline1d copy()
public boolean equals(LinearSpline1d spline)
spline
- spline to compare to this onetrue
if the splines are equalpublic LinearSpline1d clone()
clone
in interface Clonable
clone
in class Diff1Function1x1Base