Reply to topic

Problem solving linear system for VectorXf and MatrixXf

ymorinrivest
Registered Member
Posts
6
Karma
0
Hi everyone,

I have encountered a problem, and i wanted to know if anyone had faced the same issue.

I want to find b in Ax = b, so i was using VectorXd and MatrixXd and the following line
Code: Select all
xVector = aMatrix.ldlt().solve(bVector);


and everything was working perfectly fine. I decided to change the VectorXd to VectorXf and MatrixXd to MatrixXf because I was puttting float in the container anyway. Using the float version made it not work.

I then tried using the fullPivLU solver and they both worked. Is there a reason why the ldlt solver did not work on the float version of the container even if both the float and double version of the container were populated from float data.

I still have the matrix and vector in txt format if anyone is interested...
User avatar ggael
Moderator
Posts
2193
Karma
15
OS
Hi,

that happens: a LDLT factorization will lost accuracy if the matrix is not diagonal dominant, while a full pivoting LU will move largest values to the diagonal (and break the original symmetry). It would still be interesting to see your matrix to check there is really nothing to worry.
ymorinrivest
Registered Member
Posts
6
Karma
0
The curious thing is still that the system can be solved using the double version but not the float for ldlt.
If anyone is interested, here are the matrix and vector i am using :
https://docs.google.com/open?id=0B31wzs ... m91MVBjOGM
Dee33
Registered Member
Posts
54
Karma
0
OS
Your matrix is actually badly conditioned. The condition number is around 1e+18
You can check it by computing the ratio between the maximum singular value and the minimum one.
So, you should stick to a robust solver, LU with pivoting or QR
or change the model that generates the linear problem.
Hope it helps
ymorinrivest
Registered Member
Posts
6
Karma
0
Thank you for all your answers. There is still one thing that I don't understand: why are the result of the solver different when using MatrixXd and MatrixXf ( by different i mean one is not working and the other is).
Dee33
Registered Member
Posts
54
Karma
0
OS
I think it is exactly because of the bad condition number: http://en.wikipedia.org/wiki/Condition_number
Having a condition number of 1e+18 means that you can loose up to 18 digits of accuracy due to round-off errors.
These round-off errors depend on the robustness of the numerical method and the representation of floating point numbers.
single precision is not good for your problem, only the 8 first digits are the most significant. with double precision, you need a robust solver. You can also try quadruple precision.
ymorinrivest
Registered Member
Posts
6
Karma
0
That make sense, thank for all the answers ! :)

 
Reply to topic

Bookmarks



Who is online

Registered users: alake, Baidu [Spider], Bing [Bot], boudewijn, brandy_000, bshah, cristian.onet, Exabot [Bot], garthecho, Google [Bot], GreatEmerald, Horus, ken300, koriun, Majestic-12 [Bot], mgraesslin, parzt, peje, Tuukka, vomus, Yahoo [Bot]