7 #ifndef BALL_MATHS_ROMBERGINTEGRATOR_H
8 #define BALL_MATHS_ROMBERGINTEGRATOR_H
10 #ifndef BALL_MATHS_NUMERICALINTERGRATOR_H
19 template <
typename Function,
typename DataType>
70 DataType
integrate(DataType from, DataType to);
82 DataType
trapezoid(DataType
h, DataType from, DataType to);
93 template<
typename Function,
typename DataType>
100 template<
typename Function,
typename DataType>
106 template<
typename Function,
typename DataType>
112 template<
typename Function,
typename DataType>
119 maxNumSteps_ = romint.maxNumSteps_;
120 epsilon_ = romint.epsilon_;
121 result_ = romint.result_;
125 template<
typename Function,
typename DataType>
132 template<
typename Function,
typename DataType>
139 template<
typename Function,
typename DataType>
143 maxNumSteps_ = nsteps;
144 result_.reserve(maxNumSteps_ / 10);
147 template<
typename Function,
typename DataType>
153 return ((function_ == romint.function_)
154 && (epsilon_ == romint.epsilon_ )
155 && (maxNumSteps_ == romint.maxNumSteps_)
156 && (result_ == romint.result_ ));
159 template<
typename Function,
typename DataType>
164 DataType helper = (to - from);
167 Size nsteps = (
Size) (sqrt((helper*helper)/(h*
h)));
168 for (count=1; count<nsteps-1; count++)
170 sum +=function_(from+(count*h));
173 sum+=function_(from)+function_(to);
180 template<
typename Function,
typename DataType>
183 (DataType from, DataType to)
186 result_.push_back(trapezoid(h, from, to));
195 result_.push_back(trapezoid(h/((
float) i+1), from, to));
197 for (j=1; j <= i; j++)
199 result_.push_back(result_[(i*(i+1))/2 + (j-1)] + 1. / (pow(4, j) - 1) * (result_[(i*(i+1))/2 + j-1 - result_[((i-1)*i)/2+j-1]));
203 dev = result_[((i-2)*(i-1))/2+(i-2)] - result_[((i-1)*(i))/2+(i-1)];
204 }
while ( (sqrt(dev*dev) > epsilon_) && (count < maxNumSteps_));
206 return (result_[((i-1)*(i))/2 + (i-1)]);
210 #endif // BALL_MATHS_ROMBERGINTEGRATOR_H
vector< DataType > result_
#define BALL_CREATE(name)
BALL_EXTERN_VARIABLE const double E
Euler's number - base of the natural logarithm.
bool operator==(const RombergIntegrator &romint) const
Equality operator.
void setEpsilon(float eps)
Set the upper bound for the error we want to allow.
DataType integrate(DataType from, DataType to)
void setMaxNumSteps(Size mns)
Set the maximum number of steps we want to use in computation.
BALL_EXTERN_VARIABLE const double h
~RombergIntegrator()
Destructor.
virtual void clear()
Clear method.
RombergIntegrator(float epsilon=1E-5, Size nsteps=1000)
Default constructor.
DataType trapezoid(DataType h, DataType from, DataType to)
const RombergIntegrator & operator=(const RombergIntegrator &romint)
Assignment operator.