13 const Container<Number>& X,
14 const Container<Number>& Y,
15 const Container<Number>& xx,
17 Number epsilon = std::numeric_limits<Number>::epsilon()
19 if (X.size() != Y.size()) {
20 std::cerr <<
"Error in function " << __FUNCTION__
21 <<
": Vectors X (of size " << X.size()
22 <<
") and Y (of size " << Y.size()
23 <<
") are not the same size. Returning an empty array..." << std::endl;
28 std::cerr <<
"Error in function " << __FUNCTION__
29 <<
": Vectors X and Y are empty. Cannot interpolate. Returning an empty array..." << std::endl;
33 const auto N = X.size();
35 Container<Number> c(N);
38 for (
SizeT j = 1; j <= N / 2; ++j) {
39 c[j] = -c[j-1] * (
static_cast<Number
>(N - j)) /
static_cast<Number
>(j);
41 for (
SizeT j = N / 2 + 1; j < N; ++j) {
43 c[j] = std::abs(c[N-1-j]);
45 c[j] = -std::abs(c[N-1-j]);
57 for (
SizeT j = 0; j < N; ++j) {
58 c[j] = (j % 2 == 0 ? 1 : -1) * sin(((2 *
static_cast<Number
>(j) + 1) * M_PI) / (2 *
static_cast<Number
>(N)));
61 for (
SizeT j = 0; j < N; ++j) {
62 c[j] = (j % 2 == 0 ? 1 : -1) * (j == 0 || j == N - 1 ?
static_cast<Number
>(1)/
static_cast<Number
>(2) :
static_cast<Number
>(1));
68 for (
SizeT j = 0; j < N; ++j) {
70 for (
SizeT k = 0; k < N; ++k) {
73 c[j] /= (X[j] - X[k]);
79 const auto nn = xx.size();
81 Container<Number> result(nn);
83#if defined(_OPENMP) && !defined(ALFI_DISABLE_OPENMP)
84#pragma omp parallel for
86 for (
SizeT k = 0; k < nn; ++k) {
87 Number numerator = 0, denominator = 0;
90 for (
SizeT i = 0; i < N; ++i) {
95 const auto x_diff = xx[k] - X[i];
96 const auto temp = c[i] / x_diff;
97 numerator += temp * Y[i];
101 if (exact_idx != N) {
102 result[k] = Y[exact_idx];
104 result[k] = numerator / denominator;