interpolation1d
done single-threded 1d interpolations; linear, rational, cubic spline, polynomial and barycentric. Still not done test functions yet. Still missing multi-core options.
This commit is contained in:
+63
-4
@@ -3,21 +3,80 @@
|
||||
#include "./decomp/decomp.h"
|
||||
#include "./core/omp_config.h"
|
||||
|
||||
#include "./modules/grid1d.h"
|
||||
#include "./modules/finitedifference1d.h"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
//#include "./numerics/interpolation/interpolation_linear.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
|
||||
|
||||
utils::Md A;
|
||||
decomp::LUdcmpd lu(A);
|
||||
utils::Vector<double> x(100, 0), y(100,0);
|
||||
for (uint64_t i = 0; i < 100; ++i){
|
||||
x[i] = i+1;
|
||||
y[i] = 1 + i*0.1;
|
||||
}
|
||||
//y[9] = 1.5;
|
||||
|
||||
// Single-level, 16 threads, runtime may adjust
|
||||
//omp_configure(/*max_levels=*/1, /*dynamic=*/true, /*threads_per_level=*/{16});
|
||||
x.print();
|
||||
y.print();
|
||||
|
||||
double p = 5.5;
|
||||
|
||||
|
||||
|
||||
numerics::interp_linear<double> linear(x,y);
|
||||
numerics::interp_polynomial<double> polynomial(x,y, 3);
|
||||
numerics::interp_cubic_spline<double> cubic_spline(x,y);
|
||||
numerics::interp_rational<double> rational(x,y,2);
|
||||
numerics::interp_barycentric<double> barycentric(x,y, 2);
|
||||
|
||||
std::cout << "=== interpolate: " << p << " ===" << std::endl;
|
||||
|
||||
std::cout << linear.interp(p) << std::endl;
|
||||
std::cout << linear.interp(p) << std::endl;
|
||||
std::cout << polynomial.interp(p) << std::endl; // error = polynomial.dy
|
||||
std::cout << cubic_spline.interp(p) << std::endl;
|
||||
std::cout << rational.interp(p) << std::endl;
|
||||
std::cout << barycentric.interp(p) << std::endl;
|
||||
|
||||
p += 0.01;
|
||||
|
||||
std::cout << "=== interpolate: " << p << " ===" << std::endl;
|
||||
|
||||
std::cout << linear.interp(p) << std::endl;
|
||||
std::cout << polynomial.interp(p) << std::endl;
|
||||
std::cout << cubic_spline.interp(p) << std::endl;
|
||||
std::cout << rational.interp(p) << std::endl;
|
||||
std::cout << barycentric.interp(p) << std::endl;
|
||||
|
||||
p += 0.01;
|
||||
|
||||
std::cout << "=== interpolate: " << p << " ===" << std::endl;
|
||||
|
||||
std::cout << linear.interp(p) << std::endl;
|
||||
std::cout << polynomial.interp(p) << std::endl;
|
||||
std::cout << cubic_spline.interp(p) << std::endl;
|
||||
std::cout << rational.interp(p) << std::endl;
|
||||
std::cout << barycentric.interp(p) << std::endl;
|
||||
|
||||
p += 50.01;
|
||||
|
||||
std::cout << "=== interpolate: " << p << " ===" << std::endl;
|
||||
|
||||
std::cout << linear.interp(p) << std::endl;
|
||||
std::cout << polynomial.interp(p) << std::endl;
|
||||
std::cout << cubic_spline.interp(p) << std::endl;
|
||||
std::cout << rational.interp(p) << std::endl;
|
||||
std::cout << barycentric.interp(p) << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user