Loading...
Searching...
No Matches
numericalIntegrator.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: numericalIntegrator.h,v 1.18 2004/05/27 19:49:42 oliver Exp $
//
#ifndef BALL_MATHS_NUMERICALINTEGRATOR_H
#define BALL_MATHS_NUMERICALINTEGRATOR_H
#ifndef BALL_MATHS_FUNCTION_H
# include <BALL/MATHS/function.h>
#endif
namespace BALL
{
template <typename Function, typename DataType = float>
class NumericalIntegrator
{
public:
BALL_CREATE(NumericalIntegrator)
NumericalIntegrator();
NumericalIntegrator(const NumericalIntegrator& nint);
virtual ~NumericalIntegrator();
NumericalIntegrator& operator = (const NumericalIntegrator& nint);
bool operator == (const NumericalIntegrator& nint) const;
void setFunction(const Function& function);
const Function& getFunction() const { return function_; }
Function& getFunction() { return function_; }
DataType getValue(const DataType& x) const;
DataType integrate(const DataType& from, const DataType& to) const;
protected:
//_ The function to be integrated
Function function_;
};
template<typename Function, typename DataType>
BALL_INLINE
NumericalIntegrator<Function, DataType>::NumericalIntegrator()
: function_()
{
}
template<typename Function, typename DataType>
BALL_INLINE
NumericalIntegrator<Function, DataType>::NumericalIntegrator(const NumericalIntegrator<Function, DataType>& nint)
: function_(nint.function_)
{
}
template<typename Function, typename DataType>
BALL_INLINE
NumericalIntegrator<Function, DataType>::~NumericalIntegrator()
{
}
template<typename Function, typename DataType>
BALL_INLINE
NumericalIntegrator<Function, DataType>&
NumericalIntegrator<Function, DataType>::operator =
(const NumericalIntegrator<Function, DataType>& nint)
{
function_ = nint.function_;
return *this;
}
template<typename Function, typename DataType>
BALL_INLINE
void NumericalIntegrator<Function, DataType>::setFunction(const Function& function)
{
function_ = function;
}
template<typename Function, typename DataType>
BALL_INLINE
bool NumericalIntegrator<Function, DataType>::operator ==
(const NumericalIntegrator<Function, DataType>& nint) const
{
return (function_ == nint.function_);
}
template<typename Function, typename DataType>
BALL_INLINE
DataType NumericalIntegrator<Function, DataType>::getValue(const DataType& x) const
{
return function_(x);
}
template<typename Function, typename DataType>
BALL_INLINE
DataType NumericalIntegrator<Function, DataType>::integrate(
const DataType& from, const DataType& to) const
{
// ?????
// the number of samples has to be user configurable
Size samples = 30;
Size n = samples;
DataType area = 0;
DataType step = (to - from) / n;
DataType x = from;
while (n > 0)
{
area += (function_(x) + function_(x + step)) / 2.0 * step;
x += step;
--n;
}
return area;
}
}
#endif // BALL_MATHS_NUMERICALINTEGRATOR_H
BALL::NumericalIntegrator
Definition numericalIntegrator.h:21
BALL::NumericalIntegrator::function_
Function function_
Definition numericalIntegrator.h:97
BALL::NumericalIntegrator::getValue
DataType getValue(const DataType &x) const
Definition numericalIntegrator.h:155
BALL::NumericalIntegrator::getFunction
const Function & getFunction() const
Definition numericalIntegrator.h:71
BALL::NumericalIntegrator::~NumericalIntegrator
virtual ~NumericalIntegrator()
Destructor.
Definition numericalIntegrator.h:120
BALL::NumericalIntegrator::NumericalIntegrator
NumericalIntegrator()
Default constructor.
Definition numericalIntegrator.h:104
BALL::NumericalIntegrator::integrate
DataType integrate(const DataType &from, const DataType &to) const
Definition numericalIntegrator.h:163
BALL::NumericalIntegrator::getFunction
Function & getFunction()
Definition numericalIntegrator.h:76
BALL::NumericalIntegrator< Function, DataType >::setFunction
void setFunction(const Function &function)
Definition numericalIntegrator.h:138
Function
BALL_CREATE
#define BALL_CREATE(name)
Definition create.h:62
BALL_INLINE
#define BALL_INLINE
Definition debug.h:15
function.h
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114