forked from aportelli/LatAnalyze
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexInterp.cpp
31 lines (26 loc) · 1 KB
/
exInterp.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
#include <LatAnalyze/TabFunction.hpp>
int main(void)
{
Latan::DVec xs(3);
xs << -1.0, 0.0, 1.0;
Latan::DVec ys(3);
ys << 1.0, 0.0, 1.0;
auto tab = Latan::TabFunction(xs, ys, Latan::InterpType::QUADRATIC);
std::cout << "Interpolating naive y = x^2 data using quadratic ";
std::cout << "interpolation..." << std::endl;
for (double x = -1.0; x < 1.0; x += 0.1) {
double y = tab(&x);
std::cout << "y @ " << x << " = " << y;
std::cout << " ( " << x * x << " expected)" << std::endl;
}
std::cout << std::endl;
tab = Latan::TabFunction(xs, ys, Latan::InterpType::NEAREST);
std::cout << "Interpolating naive y = x^2 data using nearest ";
std::cout << "interpolation..." << std::endl;
for (double x = -1.0; x < 1.0; x += 0.1) {
double y = tab(&x);
std::cout << "y @ " << x << " = " << y;
double expected = (x > 0.5) ? 1.0 : ((x <= -0.5) ? 1.0 : 0.0);
std::cout << " ( " << expected << " expected)" << std::endl;
}
}