Rev | Line | |
---|
[136] | 1 | #include <Eigen/Dense>
|
---|
| 2 | #include <iostream>
|
---|
| 3 |
|
---|
| 4 | using namespace Eigen;
|
---|
| 5 | using namespace std;
|
---|
| 6 |
|
---|
| 7 | int main(int, char**)
|
---|
| 8 | {
|
---|
| 9 | cout.precision(3);
|
---|
| 10 | MatrixXd A = MatrixXd::Random(3,3);
|
---|
| 11 | MatrixXd B = MatrixXd::Random(3,2);
|
---|
| 12 | cout << "Here is the invertible matrix A:" << endl << A << endl;
|
---|
| 13 | cout << "Here is the matrix B:" << endl << B << endl;
|
---|
| 14 | MatrixXd X = A.lu().solve(B);
|
---|
| 15 | cout << "Here is the (unique) solution X to the equation AX=B:" << endl << X << endl;
|
---|
| 16 | cout << "Relative error: " << (A*X-B).norm() / B.norm() << endl;
|
---|
| 17 |
|
---|
| 18 | return 0;
|
---|
| 19 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.