-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmaths_textbook.cpp
More file actions
executable file
·37 lines (26 loc) · 946 Bytes
/
maths_textbook.cpp
File metadata and controls
executable file
·37 lines (26 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// maths_textbook.cpp
//
// Modified by Patrick Anderson on 07/05/2015.
// "maths_textbook" is a container for mathematical constants.
//
#include "maths_textbook.hpp"
#include <cmath>
#include <Eigen/Dense>
using namespace Eigen;
//------------------------------------------------------------------------------------------------//
// Class implementation
//------------------------------------------------------------------------------------------------//
// Constructor
maths_textbook::maths_textbook() {
// Geometry
pi = std::acos(-1.0);
}
//------------------------------------------------------------------------------------------------//
// Trapezoidal integration, vectorized
double maths_textbook::trapz(ArrayXd x_, ArrayXd y_){
int N = x_.rows() - 1;
ArrayXd x_temp = x_.tail(N) - x_.head(N);
ArrayXd y_temp = y_.tail(N) + y_.head(N);
return(0.5 * (x_temp * y_temp).sum());
}