2015-11-12 13:14:10 +00:00
|
|
|
#include <LatAnalyze/TabFunction.hpp>
|
|
|
|
|
2016-03-08 19:39:05 +00:00
|
|
|
int main(void)
|
2015-11-12 13:14:10 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2015-11-23 13:57:19 +00:00
|
|
|
std::cout << "Interpolating naive y = x^2 data using quadratic ";
|
|
|
|
std::cout << "interpolation..." << std::endl;
|
2015-11-12 13:14:10 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-11-23 13:57:19 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-03-08 19:39:05 +00:00
|
|
|
}
|