1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 00:45:36 +00:00

Examples: Added example for nearest interpolation algorithm.

This commit is contained in:
Matt Spraggs 2015-11-23 13:57:19 +00:00
parent 5283754008
commit 3c03d6d76e

View File

@ -29,10 +29,23 @@ int main(int argc, char* argv[])
auto tab = Latan::TabFunction(xs, ys, Latan::InterpType::QUADRATIC); auto tab = Latan::TabFunction(xs, ys, Latan::InterpType::QUADRATIC);
std::cout << "Interpolating naive y = x^2 data..." << std::endl; 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) { for (double x = -1.0; x < 1.0; x += 0.1) {
double y = tab(&x); double y = tab(&x);
std::cout << "y @ " << x << " = " << y; std::cout << "y @ " << x << " = " << y;
std::cout << " ( " << x * x << " expected)" << std::endl; 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;
}
} }