-
Notifications
You must be signed in to change notification settings - Fork 0
/
basis.cpp
41 lines (35 loc) · 1016 Bytes
/
basis.cpp
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
38
39
40
/// Copyright 2016 Thomas E. Vaughan
///
/// The present software is redistributable under the terms of the GNU LESSER
/// GENERAL PUBLIC LICENSE, which must be distributed in the file, 'LICENSE',
/// along with the software.
///
/// \file basis.cpp
/// \brief Definition of linreg::polynomial_basis, linreg::fourier_basis.
#include <cmath> // for cos(), sin()
#include "basis.hpp"
using namespace Eigen;
using namespace linreg;
VectorXd polynom_basis::operator()(double const x) const
{
unsigned const sz = size();
VectorXd result(sz);
result(0) = 1.0;
for (unsigned i = 1; i < sz; ++i) {
result(i) = result(i - 1) * x;
}
return result;
}
VectorXd fourier_basis::operator()(double const x) const
{
unsigned const sz = size();
VectorXd result(sz);
result(0) = 1.0;
for (unsigned i = 1; i < sz; i += 2) {
unsigned const j = (i + 1) / 2;
double const k = j * angfreq_;
result(i + 0) = cos(k * x);
result(i + 1) = sin(k * x);
}
return result;
}