-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_diff_mat.cpp
86 lines (77 loc) · 2.21 KB
/
test_diff_mat.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
// to test Differentiation Matrix over Chebyshev polynomial
// g++ -I/home/iota/Desktop/sliding_stone test_diff_mat.cpp -o test_diff_mat
#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <iomanip>
#include "Differentiation_Matrix.cpp"
#define PI acos(-1)
#define f(val) sin(val)
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
freopen("test_input.txt", "r", stdin);
//freopen("test_output.txt", "w", stdout);
int n;
cin >> n;
std::vector<double > X(n + 1), P(n + 1), C(n + 1), T(n + 1), t(n + 1);
std::vector < std::vector<double > > D(n + 1 , std::vector <double > (n + 1));
T = define_time_stamps<double, int>(n + 1);
//cout << endl;
// for (int i = 0 ; i <=n ; i++) {
//cout <<double(i)<< ","<<T[i] << "\n";
//} //cout << endl;
//decimal t_0 = (-3.0*PI) , t_f = 3.0*PI ;
decimal t_0 = -2.0, t_f = 2.0;
for (integer i = 0; i <= n; i++)
{
t[i] = ((t_f - t_0) * (T[i]) + (t_f + t_0)) / 2.0;
//myfile << "t[" << i << "]" << " : " << t[i] << std::endl;
}
std::ofstream myfile;
myfile.open("test_output_1.txt");
for (int i = 0 ; i <= n ; i++) {
//X[i] = f(t[i]);
X[i] = t[i];
//X[i] =t[i]*t[i];
myfile<< t[i] << "," << X[i] << "\n";
}
myfile.close();
C = compute_c<double, int>(n + 1);
// cout << endl;
// for (int i = 0 ; i < n ; i++) {
// cout << i << "," << C[i] << "\n";
// } cout << endl;
D = formulate_differentiation_matrix<double, int>(C, T, n + 1);
std::cout.precision(4);
/*
for (int k = 0 ; k <=n; k++)
{
double sum=0;
for (int j = 0 ; j <=n ; j++)
{
sum+=D[j][k];
//cout << D[j][k] << " ";
} cout <<sum<< endl<<endl;
}
*/
P = multiply_D_X<double, int>(D, X, n + 1);
// scale P
/*
decimal x_0 = f(t_0), x_f = f(t_f);
for (integer i = 0; i <= n; i++)
{
P[i] = ((x_f - x_0) * (P[i]) + (x_f + x_0)) / 2.0;
//std::cout << "t[" << i << "]" << " : " << t[i] << std::endl;
}*/
//std::ofstream myfile;
myfile.open("test_output_2.txt");
for (int i = 0 ; i <= n ; i++) {
//cout << ((tf / 2.0) * (T[i] + 1)) << "," << ((pf / 2.0) * (P[i] + 1)) << "\n";
//cout << ((tf / 2.0) * (T[i] + 1)) << "," << P[i] << "\n";
myfile << t[i] << "," << (2.0/(t_f-t_0))*P[i] << "\n";
}
myfile.close();
return 0;
}