vec_math
Class SimpleIntegrator

java.lang.Object
  extended by vec_math.SimpleIntegrator
All Implemented Interfaces:
Integrator

public class SimpleIntegrator
extends Object
implements Integrator

The simpliest Integrator possible. Implements a trapezoid-integrator. Only the accumulated sum is stored. Highly inefficient if used with setting of huge data sets.

Note that it is within the user's responsibility to correctly initialize the numerical integrator with a call to initData(double, double) prior to calling the one of the add(double, double) methods.


Nested Class Summary
static class SimpleIntegrator.E
          Tests the integrator.
static class SimpleIntegrator.Gauss
          Tests the integrator.
static class SimpleIntegrator.Xsquare
          Tests the integrator.
 
Field Summary
private  double xprior
          The x-value prior-to-last.
private  double yprior
          The y-value prior-to-last.
private  double ysum
          The accumulated sum, i.e.
 
Constructor Summary
SimpleIntegrator()
           
 
Method Summary
 void add(double y)
          Adds a new y-data point with a step-size of one.
 void add(double x, double y)
          Adds a new x/y data point.
private  void addTrapezoid(double base, double ynew)
          This private method calculates the area of an trapezoid and adds it to the accumulated sum in ysum.
 double getIntegral()
          Calculates the difference at the last points added.
 double getIntegral(double x)
          Cannot compute.
 void initData(double xstart, double ystart)
          Initializes the integrator.
 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)
          Lengthy implementation erasing all old data and step-by-step adding the new one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xprior

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


yprior

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


ysum

private double ysum
The accumulated sum, i.e. the integral.

Constructor Detail

SimpleIntegrator

public SimpleIntegrator()
Method Detail

initData

public void initData(double xstart,
                     double ystart)
Initializes the integrator. Here, it sets the two x/y prior-data, i.e. xprior and yprior. Additionally, the accumulated sum is set to zero.

Specified by:
initData in interface Integrator

add

public void add(double x,
                double y)
Adds a new x/y data point. Uses the xprior value to calculate a step-size and then calls addTrapezoid(double, double).

Specified by:
add in interface Integrator
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 with a step-size of one.

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

addTrapezoid

private void addTrapezoid(double base,
                          double ynew)
This private method calculates the area of an trapezoid and adds it to the accumulated sum in ysum. Additionally, the y-prior value is updated to the new y value.


setData

public void setData(double[] x,
                    double[] y)
Lengthy implementation erasing all old data and step-by-step adding the new one. Calls initData(double, double) with the first x/y pair and then continuously adds new data with the add(double, double) method.

Specified by:
setData in interface Integrator
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 Integrator
Parameters:
y - A double-array representing the y-axis values.

getIntegral

public double getIntegral()
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:
getIntegral in interface Integrator
Returns:
The difference of the y-values devided by the stepsize in x.

getIntegral

public double getIntegral(double x)
Cannot compute.

Specified by:
getIntegral in interface Integrator