BALL 1.5.0
numericalIntegrator.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4// $Id: numericalIntegrator.h,v 1.18 2004/05/27 19:49:42 oliver Exp $
5//
6
7#ifndef BALL_MATHS_NUMERICALINTEGRATOR_H
8#define BALL_MATHS_NUMERICALINTEGRATOR_H
9
10#ifndef BALL_MATHS_FUNCTION_H
11# include <BALL/MATHS/function.h>
12#endif
13
14namespace BALL
15{
19 template <typename Function, typename DataType = float>
21 {
22
23 public:
24
26
27
29
30
32
35
38
40
41
43
44
46 NumericalIntegrator& operator = (const NumericalIntegrator& nint);
47
49
50
52
53
55 bool operator == (const NumericalIntegrator& nint) const;
56
58
59
61
62
66 void setFunction(const Function& function);
67
71 const Function& getFunction() const { return function_; }
72
77
82 DataType getValue(const DataType& x) const;
83
89 DataType integrate(const DataType& from, const DataType& to) const;
90
92
93
94 protected:
95
96 //_ The function to be integrated
98
99 };
100
101
102 template<typename Function, typename DataType>
105 : function_()
106 {
107 }
108
109
110 template<typename Function, typename DataType>
113 : function_(nint.function_)
114 {
115 }
116
117
118 template<typename Function, typename DataType>
121 {
122 }
123
124
125 template<typename Function, typename DataType>
130 {
131 function_ = nint.function_;
132 return *this;
133 }
134
135
136 template<typename Function, typename DataType>
139 {
140 function_ = function;
141 }
142
143
144 template<typename Function, typename DataType>
148 {
149 return (function_ == nint.function_);
150 }
151
152
153 template<typename Function, typename DataType>
156 {
157 return function_(x);
158 }
159
160
161 template<typename Function, typename DataType>
164 const DataType& from, const DataType& to) const
165 {
166 // ?????
167 // the number of samples has to be user configurable
168 Size samples = 30;
169 Size n = samples;
170
171 DataType area = 0;
172 DataType step = (to - from) / n;
173 DataType x = from;
174
175 while (n > 0)
176 {
177 area += (function_(x) + function_(x + step)) / 2.0 * step;
178 x += step;
179 --n;
180 }
181
182 return area;
183 }
184}
185
186#endif // BALL_MATHS_NUMERICALINTEGRATOR_H
#define BALL_CREATE(name)
Definition: create.h:62
#define BALL_INLINE
Definition: debug.h:15
Definition: constants.h:13
DataType getValue(const DataType &x) const
const Function & getFunction() const
virtual ~NumericalIntegrator()
Destructor.
NumericalIntegrator()
Default constructor.
DataType integrate(const DataType &from, const DataType &to) const
void setFunction(const Function &function)