This forum has been archived. All content is frozen. Please use KDE Discuss instead.

LU decomposition am I doing this rite?

Tags: None
(comma "," separated)
wingsit
Registered Member
Posts
28
Karma
0
OS
Hi all

I have the following code #include <iostream>
#include <string>
#include <Eigen/Dense>


using std::cout;
using std::endl;
using namespace Eigen;

#define n 5

int main(){
MatrixXd m = MatrixXd::Random(n,n);

cout << m.lu().matrixLU() << endl;
cout << endl;

MatrixXd l= MatrixXd::Identity(n,n);
MatrixXd u= MatrixXd::Zero(n,n);

(l=m.lu().matrixLU().triangularView<StrictlyLower>()) += MatrixXd::Identity(n,n);
u=m.lu().matrixLU().triangularView<Upper>();

cout << l << endl<<endl;
cout << u << endl;

cout << "Are they equal" << endl;
cout << m.lu().permutationP().inverse()*( l*u) << endl;
cout << endl;
cout << m.lu().reconstructedMatrix() << endl;

// cout << m << endl;

cout << endl;


}

when I compute m.lu().permutationP().inverse()*( l*u) shouldn't this be equal to m?

Any thought is appreciated. Thanks!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
hm yes, and here they are indeed equal.... what's the matter?

Note that you can also use "m.lu().matrixLU().triangularView<UnitLower>()" instead of adding the identity matrix.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora