NumCpp
2.16.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
trapazoidal.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
trapazoidal
(
const
double
low
,
52
const
double
high
,
53
const
uint32
n
,
54
const
std::function<
double
(
double
)>& f)
noexcept
55
{
56
const
double
width = (
high
-
low
) /
static_cast<
double
>
(
n
);
57
58
double
trapezoidal_integral
= 0.;
59
for
(
uint32
step = 0; step <
n
; ++step)
60
{
61
const
double
x1
=
low
+
static_cast<
double
>
(step) * width;
62
const
double
x2
=
low
+
static_cast<
double
>
(step + 1) * width;
63
64
trapezoidal_integral
+= 0.5 * (
x2
-
x1
) * (f(
x1
) + f(
x2
));
65
}
66
67
return
trapezoidal_integral
;
68
}
69
}
// namespace nc::integrate
Types.hpp
nc::integrate
Definition
gauss_legendre.hpp:43
nc::integrate::trapazoidal
double trapazoidal(const double low, const double high, const uint32 n, const std::function< double(double)> &f) noexcept
Definition
trapazoidal.hpp:51
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
trapazoidal.hpp
Generated by
1.9.8