Reputation: 49
I have two matrices J1 (sparse) = J2(full).
The dimension of the matrices are ~ 5200x2600
Then when I do:
hlm1 = (J1'*J1 + u*I)\g, I = eye(n);
and
hlm2 = (J2'*J2 + u*I)\g, I = eye(n);
i have after that: norm(hlm1 - hlm12, Inf)
is 4.8625e-05
...
That difference is my problem, is correct the way to use the matrice sparse ?.
Thx.
Upvotes: 1
Views: 143
Reputation: 8459
This is not a complete answer, but I think it could be useful. I can partially reproduce this difference using some random data:
H1=sprand(1000,1000,.4);
g=sprand(1000,1,.5);
x=H1*g;
H2=full(H1);
x2=full(x);
g1=H1\x;
g2=H2\x2;
difference=norm(g1-g2,Inf)
errorSparse=norm(g1-g,Inf)
errorFull=norm(g2-g,Inf)
the norm ends up roughly O(1e-12). I think the difference is due to the method used to solve sparse system of equations. Solving the sparse system will be using sparse function, and solving the full matrix will be using a different set of functions. Naturally these functions will be different, and I think this is probably causing some differences. I can't explain why the errors are that large though.
See the documentation for mldivide
which includes some short discussion about sparse matrices as well as some methods use to solve them.
Upvotes: 1