vec_math
Class SimpleDifferentiator

java.lang.Object
  extended by vec_math.SimpleDifferentiator
All Implemented Interfaces:
Differentiator

public class SimpleDifferentiator
extends Object
implements Differentiator

The simpliest Differentiator possible. Take the last two y-values and divide their difference by the stepsize.


Nested Class Summary
static class SimpleDifferentiator.E
          Tests the integrator.
 
Field Summary
private  double xlast
          The x-value at the last call to add.
private  double xprior
          The x-value prior-to-last.
private  double ylast
          The y-value at the last call to add.
private  double yprior
          The y-value prior-to-last.
 
Constructor Summary
SimpleDifferentiator()
          Defaults the xprior to zero and the xlast value to one, mimicing a step-size of one.
 
Method Summary
 void add(double y)
          Adds a new y-data point.
 void add(double x, double y)
          Adds a new x/y data point.
 double getDerivative()
          Calculates the difference at the last points added.
 double getDerivative(double x)
          Cannot compute.
 void setData(double[] y)
          Takes the last two y-values as the last and prior-to-last y value.
 void setData(double[] x, double[] y)
          Takes the last two values of x and stores them for the step size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xlast

private double xlast
The x-value at the last call to add.


xprior

private double xprior
The x-value prior-to-last.


ylast

private double ylast
The y-value at the last call to add.


yprior

private double yprior
The y-value prior-to-last.

Constructor Detail

SimpleDifferentiator

public SimpleDifferentiator()
Defaults the xprior to zero and the xlast value to one, mimicing a step-size of one. This step-size is used in equally-spaced differentiator methods, where x is never set.

Method Detail

setData

public void setData(double[] x,
                    double[] y)
Takes the last two values of x and stores them for the step size. Then calls the set-data method with the y-array as an argument. Note that for high-speed, only equal-step size should be used, calling directly the set-data-in-y method.

Specified by:
setData in interface Differentiator
Parameters:
x - A double-array representing the x-axis values.
y - A double-array representing the y-axis values.

setData

public void setData(double[] y)
Takes the last two y-values as the last and prior-to-last y value.

Specified by:
setData in interface Differentiator
Parameters:
y - A double-array representing the y-axis values.

add

public void add(double x,
                double y)
Adds a new x/y data point. Transfers xlast to xprior and stors the x-value passed over in xlast. Then, call the add-method with the y-value alone.

Specified by:
add in interface Differentiator
Parameters:
x - A newly added x-value.
y - A newly added y-value.

add

public void add(double y)
Adds a new y-data point. Transfers ylast to yprior and stors the y-value passed over in ylast.

Specified by:
add in interface Differentiator
Parameters:
y - A newly added y-value.

getDerivative

public double getDerivative()
Calculates the difference at the last points added. If the equal- stepped version is used, the step size is calculated from the default setting done in the construction phase. Note that deliberate missuse (i.e. calling add with x/y, then adding only y values) can yield wrong results.

Specified by:
getDerivative in interface Differentiator
Returns:
The difference of the y-values devided by the stepsize in x.

getDerivative

public double getDerivative(double x)
Cannot compute.

Specified by:
getDerivative in interface Differentiator