TutorialInplaceLU.cpp
Go to the documentation of this file.
1 #include <iostream>
2 struct init {
3  init() { std::cout << "[" << "init" << "]" << std::endl; }
4 };
6 // [init]
7 #include <iostream>
8 #include <Eigen/Dense>
9 
10 using namespace std;
11 using namespace Eigen;
12 
13 int main()
14 {
15  MatrixXd A(2,2);
16  A << 2, -1, 1, 3;
17  cout << "Here is the input matrix A before decomposition:\n" << A << endl;
18 cout << "[init]" << endl;
19 
20 cout << "[declaration]" << endl;
22  cout << "Here is the input matrix A after decomposition:\n" << A << endl;
23 cout << "[declaration]" << endl;
24 
25 cout << "[matrixLU]" << endl;
26  cout << "Here is the matrix storing the L and U factors:\n" << lu.matrixLU() << endl;
27 cout << "[matrixLU]" << endl;
28 
29 cout << "[solve]" << endl;
30  MatrixXd A0(2,2); A0 << 2, -1, 1, 3;
31  VectorXd b(2); b << 1, 2;
32  VectorXd x = lu.solve(b);
33  cout << "Residual: " << (A0 * x - b).norm() << endl;
34 cout << "[solve]" << endl;
35 
36 cout << "[modifyA]" << endl;
37  A << 3, 4, -2, 1;
38  x = lu.solve(b);
39  cout << "Residual: " << (A0 * x - b).norm() << endl;
40 cout << "[modifyA]" << endl;
41 
42 cout << "[recompute]" << endl;
43  A0 = A; // save A
44  lu.compute(A);
45  x = lu.solve(b);
46  cout << "Residual: " << (A0 * x - b).norm() << endl;
47 cout << "[recompute]" << endl;
48 
49 cout << "[recompute_bis0]" << endl;
50  MatrixXd A1(2,2);
51  A1 << 5,-2,3,4;
52  lu.compute(A1);
53  cout << "Here is the input matrix A1 after decomposition:\n" << A1 << endl;
54 cout << "[recompute_bis0]" << endl;
55 
56 cout << "[recompute_bis1]" << endl;
57  x = lu.solve(b);
58  cout << "Residual: " << (A1 * x - b).norm() << endl;
59 cout << "[recompute_bis1]" << endl;
60 
61 }
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::PartialPivLU
LU decomposition of a matrix with partial pivoting, and related features.
Definition: ForwardDeclarations.h:269
b
Scalar * b
Definition: benchVecAdd.cpp:17
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
A0
static const double A0[]
Definition: expn.h:5
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
init::init
init()
Definition: TutorialInplaceLU.cpp:3
main
int main()
Definition: TutorialInplaceLU.cpp:13
init_obj
init init_obj
Definition: TutorialInplaceLU.cpp:5
lu
cout<< "Here is the matrix m:"<< endl<< m<< endl;Eigen::FullPivLU< Matrix5x3 > lu(m)
std
Definition: BFloat16.h:88
A1
static const double A1[]
Definition: expn.h:6
init
Definition: TutorialInplaceLU.cpp:2


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:43:01