NumCpp
2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Toggle main menu visibility
Main Page
Related Pages
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
z
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
z
Variables
a
c
d
e
g
h
i
j
m
n
o
p
s
t
v
Typedefs
Enumerations
Data Structures
Data Structures
Data Structure Index
Class Hierarchy
Data Fields
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
a
c
d
e
i
l
m
n
p
r
s
t
v
x
y
z
Typedefs
a
c
d
i
p
r
s
t
v
Enumerations
Related Symbols
Files
File List
Globals
All
Macros
Examples
•
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Loading...
Searching...
No Matches
simpson.hpp
Go to the documentation of this file.
1
32
#pragma once
33
34
#include <functional>
35
36
#include "
NumCpp/Core/Types.hpp
"
37
38
namespace
nc::integrate
39
{
40
//============================================================================
41
// Method Description:
51
inline
double
52
simpson
(
const
double
low
,
const
double
high
,
const
uint32
n
,
const
std::function<
double
(
double
)>& f)
noexcept
53
{
54
const
double
width = (
high
-
low
) /
static_cast<
double
>
(
n
);
55
56
double
simpson_integral
= 0.;
57
for
(
uint32
step = 0; step <
n
; ++step)
58
{
59
const
double
x1
=
low
+
static_cast<
double
>
(step) * width;
60
const
double
x2
=
low
+
static_cast<
double
>
(step + 1) * width;
61
62
simpson_integral
+= (
x2
-
x1
) / 6. * (f(
x1
) + 4. * f(0.5 * (
x1
+
x2
)) + f(
x2
));
63
}
64
65
return
simpson_integral
;
66
}
52
simpson
(
const
double
low
,
const
double
high
,
const
uint32
n
,
const
std::function<
double
(
double
)>& f)
noexcept
{
…
}
67
}
// namespace nc::integrate
Types.hpp
nc::integrate
Definition
gauss_legendre.hpp:43
nc::integrate::simpson
double simpson(const double low, const double high, const uint32 n, const std::function< double(double)> &f) noexcept
Definition
simpson.hpp:52
nc::arange
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition
arange.hpp:59
nc::uint32
std::uint32_t uint32
Definition
Types.hpp:40
include
NumCpp
Integrate
simpson.hpp
Generated by
1.9.8