## Problem solving linear system for VectorXf and MatrixXf

ymorinrivest
Registered Member
Posts
6
Karma
0

### Problem solving linear system for VectorXf and MatrixXf

Wed Oct 10, 2012 8:24 am
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...
ggael
Moderator
Posts
2857
Karma
18
OS

### Re: Problem solving linear system for VectorXf and MatrixXf

Wed Oct 10, 2012 8:28 pm
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

### Re: Problem solving linear system for VectorXf and MatrixXf

Thu Oct 11, 2012 12:20 am
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 :
Dee33
Registered Member
Posts
54
Karma
0
OS

### Re: Problem solving linear system for VectorXf and MatrixXf

Thu Oct 11, 2012 4:13 pm
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

### Re: Problem solving linear system for VectorXf and MatrixXf

Fri Oct 12, 2012 6:10 am
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

### Re: Problem solving linear system for VectorXf and MatrixXf

Fri Oct 12, 2012 7:15 am
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

### Re: Problem solving linear system for VectorXf and MatrixXf

Tue Oct 16, 2012 2:39 am
That make sense, thank for all the answers !

## Who is online

Registered users: AGuiFr, alainroger, Artmessiah, Baidu [Spider], Bing [Bot], cristian.onet, dinosath, Exabot [Bot], Frizou, Google [Bot], hussam, kde-doozer, Laptander, Majestic-12 [Bot], molecule-eye, prafuldevvr, sihyunp, slangkamp, starbuck, ttguy, Yahoo [Bot]