BALL
1.5.0
include
BALL
MATHS
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
14
namespace
BALL
15
{
19
template
<
typename
Function,
typename
DataType =
float
>
20
class
NumericalIntegrator
21
{
22
23
public
:
24
25
BALL_CREATE
(
NumericalIntegrator
)
26
27
28
29
30
31
NumericalIntegrator
();
32
34
NumericalIntegrator
(
const
NumericalIntegrator
& nint);
35
37
virtual
~NumericalIntegrator
();
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
76
Function&
getFunction
() {
return
function_
; }
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
97
Function
function_
;
98
99
};
100
101
102
template
<
typename
Function,
typename
DataType>
103
BALL_INLINE
104
NumericalIntegrator<Function, DataType>::NumericalIntegrator
()
105
: function_()
106
{
107
}
108
109
110
template
<
typename
Function,
typename
DataType>
111
BALL_INLINE
112
NumericalIntegrator<Function, DataType>::NumericalIntegrator
(
const
NumericalIntegrator<Function, DataType>
& nint)
113
: function_(nint.function_)
114
{
115
}
116
117
118
template
<
typename
Function,
typename
DataType>
119
BALL_INLINE
120
NumericalIntegrator<Function, DataType>::~NumericalIntegrator
()
121
{
122
}
123
124
125
template
<
typename
Function,
typename
DataType>
126
BALL_INLINE
127
NumericalIntegrator<Function, DataType>
&
128
NumericalIntegrator<Function, DataType>::operator
=
129
(
const
NumericalIntegrator<Function, DataType>
& nint)
130
{
131
function_ = nint.
function_
;
132
return
*
this
;
133
}
134
135
136
template
<
typename
Function,
typename
DataType>
137
BALL_INLINE
138
void
NumericalIntegrator<Function, DataType>::setFunction
(
const
Function&
function
)
139
{
140
function_ =
function
;
141
}
142
143
144
template
<
typename
Function,
typename
DataType>
145
BALL_INLINE
146
bool
NumericalIntegrator<Function, DataType>::operator
==
147
(
const
NumericalIntegrator<Function, DataType>
& nint)
const
148
{
149
return
(function_ == nint.function_);
150
}
151
152
153
template
<
typename
Function,
typename
DataType>
154
BALL_INLINE
155
DataType
NumericalIntegrator<Function, DataType>::getValue
(
const
DataType& x)
const
156
{
157
return
function_(x);
158
}
159
160
161
template
<
typename
Function,
typename
DataType>
162
BALL_INLINE
163
DataType
NumericalIntegrator<Function, DataType>::integrate
(
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
BALL_INLINE
#define BALL_INLINE
Definition:
debug.h:15
BALL::NumericalIntegrator::NumericalIntegrator
NumericalIntegrator()
Default constructor.
Definition:
numericalIntegrator.h:104
BALL::NumericalIntegrator::getValue
DataType getValue(const DataType &x) const
Definition:
numericalIntegrator.h:155
BALL_SIZE_TYPE
BALL::NumericalIntegrator::getFunction
Function & getFunction()
Definition:
numericalIntegrator.h:76
BALL::NumericalIntegrator::getFunction
const Function & getFunction() const
Definition:
numericalIntegrator.h:71
BALL
Definition:
constants.h:12
BALL::NumericalIntegrator::operator=
NumericalIntegrator & operator=(const NumericalIntegrator &nint)
Assignment operator.
Definition:
numericalIntegrator.h:129
BALL::NumericalIntegrator::integrate
DataType integrate(const DataType &from, const DataType &to) const
Definition:
numericalIntegrator.h:163
BALL::NumericalIntegrator::setFunction
void setFunction(const Function &function)
Definition:
numericalIntegrator.h:138
BALL::NumericalIntegrator::operator==
bool operator==(const NumericalIntegrator &nint) const
Equality operator.
Definition:
numericalIntegrator.h:147
function.h
BALL::NumericalIntegrator
Definition:
numericalIntegrator.h:20
BALL_CREATE
#define BALL_CREATE(name)
Definition:
create.h:62
BALL::NumericalIntegrator::function_
Function function_
Definition:
numericalIntegrator.h:97
BALL::NumericalIntegrator::~NumericalIntegrator
virtual ~NumericalIntegrator()
Destructor.
Definition:
numericalIntegrator.h:120
Generated by
1.8.16