vec_math
Class StepFunction

java.lang.Object
  extended by vec_math.StepFunction
All Implemented Interfaces:
Function

public class StepFunction
extends Object
implements Function

A function that is piecewise constant. It can be constructed either with a String that defines the intervall borders and the values there.


Field Summary
private  Polynom[] poly
          The polynoms describing the function in the interval.
private  double[] x
          The intervall boundaries.
 
Constructor Summary
StepFunction(String doubletokenize)
          A step function can be constructed with a twice-tokenizable string like
StepFunction(VectorG[] grid)
          Constructs a step function with a grid of sampling.
 
Method Summary
 double evaluate(double t)
          We evaluate the step function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x

private double[] x
The intervall boundaries. Intervall is from i-1 to current index.


poly

private Polynom[] poly
The polynoms describing the function in the interval.

Constructor Detail

StepFunction

public StepFunction(String doubletokenize)
A step function can be constructed with a twice-tokenizable string like
       1,2,0.4,.005;2,-3.-.4,0.01;3,1.,0.,0.
       
This string is converted into an array of VectorGs, the elements of the vector separated by comas, the vectors by semicolon.


StepFunction

public StepFunction(VectorG[] grid)
Constructs a step function with a grid of sampling. Each vector represents a sampling such that the zeroth coordinate is the upper intervall boundary and the coordinates from one up are the coefficients of polynomials defining the function in the intervall such that for each i>0
       vi-1(0)i(0),
       dx=x-vi(0),
       y=Σvi(j+1)*dx^j, j=0...v.dim-2
       
The function is in principle not defined outside the intervall x<v0(0) and x>vn-1(0), but it is simply extrapolated here. The heaviside step function can be constructed with (0,0);(inf,1)

Method Detail

evaluate

public double evaluate(double t)
We evaluate the step function. We search the index by bisection in the intervall boundaries, then use the polynomial at that index to first calculate the delta x, and then using that in the polynom.
       dx = x-x[index];
       y  = polynom[index].evaluate(dx).
       
The polynomials act on the difference to keep the coefficients handable. Note that therefore dx is always negative, except beyond the last interval border.

Specified by:
evaluate in interface Function