forked from EPCCed/archer2-cpp
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsparse.cpp
More file actions
50 lines (38 loc) · 1.11 KB
/
Copy pathsparse.cpp
File metadata and controls
50 lines (38 loc) · 1.11 KB
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
#include <Eigen/Dense>
#include <Eigen/Sparse>
#include <fstream>
#include <iostream>
#include <vector>
int main()
{
int n = 20;
int steps = 200;
Eigen::SparseMatrix<double> A;
A.resize(n, n);
double delta = 0.4;
std::vector<Eigen::Triplet<double>> fill;
fill.reserve(n * 4);
for (int i = 0; i < n - 1; ++i)
{
fill.push_back(Eigen::Triplet<double>(i + 1, i, delta));
fill.push_back(Eigen::Triplet<double>(i + 1, i + 1, -delta));
fill.push_back(Eigen::Triplet<double>(i, i, 1.0 - delta));
fill.push_back(Eigen::Triplet<double>(i, i + 1, delta));
}
fill.push_back(Eigen::Triplet<double>(n - 1, n - 1, 1.0));
A.setFromTriplets(fill.begin(), fill.end());
std::cout << A << std::endl;
Eigen::VectorXd b(n);
b.head(n / 2).array() = 1.0;
b.tail(n / 2).array() = 0.0;
std::cout << b.transpose() << std::endl;
std::ofstream f;
f.open("sparse_sim.txt");
for (int i = 0; i < steps; ++i)
{
f << b.transpose() << std::endl;
b = A * b;
}
std::cout << b.transpose() << std::endl;
return 0;
}