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

problem with a under-determined equation system

Tags: None
(comma "," separated)
ralfs
Registered Member
Posts
2
Karma
0
Hello,

im new to eigen and i try to solve this equation system:

1 -3 2 | 8
-1 3 -4 | -16

The expected solution after some pivots is:

1 -3 0 | 0
0 0 1 | 4
....
1 -3 0 | 0
0 -1 0 | 0
0 0 1 | 4
...
x1=0+3t
x2=0+1t
x3=4

So i've written this little program and it works fine:

MatrixXd A(2,3);
VectorXd b(2);
A << 1,-3,2, -1,3,-4;
b << 8,-16;
VectorXd x(3);
x = A.fullPivHouseholderQr().solve(b);
cout << "The solution is:\n" << x << endl;

...
The solution is:
0
-0
4
And this is the expected right hand side!

But how can i get the left-hand-side to see the second column?

1 -3 0
0 -1 0
0 0 1

Thanks,
Ralf
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
If you want an expression of the full space of solution, you can use FullPivLU::kernel(): http://eigen.tuxfamily.org/dox/classEig ... 13b6e7200a. The space of solution is then:

v0+lu.kernel()*x

where v0 is one solution (e.g., obtained using FullPivLU::solve) and x is any vector of size lu.kernel().cols().
ralfs
Registered Member
Posts
2
Karma
0
Thank you! That helped.

Is it possible to see the whole left hand side solution like

1 -3 0
0 -1 0
0 0 1

?

Ralf
jitseniesen
Registered Member
Posts
204
Karma
2
This is the matrix U, which you can get as in the topmost example of http://eigen.tuxfamily.org/dox/classEig ... PivLU.html . However, Eigen uses a more sophisticated algorithm which also allows for column swaps, as indicated by "full pivoting", which means you will not get the same left-hand side matrix. Instead I got

-4 3 -1
0 -1.5 0.5

We can reconstruct what Eigen does. Starting from your original matrix, Eigen swaps the rows and also first and third column, giving

-4 3 -1
2 -3 1

and then it adds 0.5 times the first row to the second row, which gives the solution as above (the first matrix in this post).


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]