-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterp.cpp
99 lines (80 loc) · 3.52 KB
/
interp.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// Created by Harold on 2020/9/16.
//
#include <cmath>
#include <iostream>
#include <vector>
#include "m_interp.h"
#include "utils.h"
using namespace M_MATH;
int main() {
size_t const N = 10;
std::vector<double> x(N), y(N), z(N*N), nx(2*N-1), ny(2*N-1), nz((2*N-1)*(2*N-1));
for (int i = 0; i < N; ++i) {
x[i] = i;
y[i] = 2*sin(i);
}
nx = linspace<double>(0, N-1, 2*N-1);
std::cout << "1d original: ";
for (auto i = 0; i < N; ++i)
std::cout << '(' << x[i] << ", " << y[i] << ')' << ' ';
std::cout << std::endl;
for (int e = Interpolation1D::LINEAR; e != Interpolation1D::STEFFEN + 1; ++e) {
Interpolation1D::interpolate(x.data(), y.data(), N, static_cast<Interpolation1D::InterpType>(e),
nx.data(), 2*N, ny.data());
std::cout << e << ": ";
for (auto i = 0; i < 2*N; ++i)
std::cout << '(' << nx[i] << ", " << ny[i] << ')' << ' ';
std::cout << std::endl;
}
std::cout << std::endl;
for (int e = Interpolation1D::LINEAR; e != Interpolation1D::STEFFEN + 1; ++e) {
Interpolation1D::interpolate(x.begin(), x.end(), y.begin(), y.end(),
static_cast<Interpolation1D::InterpType>(e),
nx.begin(), nx.end(),
ny.begin());
std::cout << e << ": ";
for (auto i = 0; i < 2*N; ++i)
std::cout << '(' << nx[i] << ", " << ny[i] << ')' << ' ';
std::cout << std::endl;
}
std::cout << "\n\n" << std::endl;
/******************************************************************************/
x = linspace<double>(0, N-1, N);
y = linspace<double>(0, N-1, N);
z = linspace<double>(0, N*N, N*N);
nx = linspace<double>(0, N-1, 2*N-1);
ny = linspace<double>(0, N-1, 2*N-1);
std::cout << "2d original: ";
for (auto i = 0; i < x.size(); ++i)
for (auto j = 0; j < y.size(); ++j)
std::cout << '(' << x[i] << ", " << y[j] << ", " << z[j * N + i] << ')' << ' ';
std::cout << std::endl;
for (int e = Interpolation2D::BI_LINEAR; e != Interpolation2D::BI_CUBIC + 1; ++e) {
Interpolation2D::interpolate(x.data(), y.data(), z.data(), x.size(), y.size(),
static_cast<Interpolation2D::InterpType>(e),
nx.data(), ny.data(), nx.size(), ny.size(),
nz.data());
std::cout << e << ": ";
for (auto i = 0; i < nx.size(); ++i)
for (auto j = 0; j < ny.size(); ++j)
std::cout << '(' << nx[i] << ", " << ny[j] << ", " << nz[j * N + i] << ')' << ' ';
std::cout << std::endl;
}
std::cout << std::endl;
for (int e = Interpolation2D::BI_LINEAR; e != Interpolation2D::BI_CUBIC + 1; ++e) {
Interpolation2D::interpolate(x.begin(), x.end(),
y.begin(), y.end(),
z.begin(), z.end(),
static_cast<Interpolation2D::InterpType>(e),
nx.begin(), nx.end(),
ny.begin(), ny.end(),
nz.begin());
std::cout << e << ": ";
for (auto i = 0; i < nx.size(); ++i)
for (auto j = 0; j < ny.size(); ++j)
std::cout << '(' << nx[i] << ", " << ny[j] << ", " << nz[j * N + i] << ')' << ' ';
std::cout << std::endl;
}
return 0;
}