How to solve a sparse matrix efficiently?
古いコメントを表示
Hallo everyone,
I am trying to solve a linear equation system A*x=b that describes a 3D grid and heat transfer between adjecent cells and mass convection by an upwind scheme. As the upwind scheme is somewhat asymmetric, the sparse Matrix that looks like the one below. So far I use x = A\b, but when the problem starts to get bigger this appears to be rather slow. Therefore I am looking for a way to speed up the computation. As the thermal conductivity and so are temperature dependent, I have to solve this equation system a couple of times till a global convergence is achieved.
There are some iterative methods implemented (<http://www.mathworks.de/de/help/matlab/linear-equations-iterative-methods.html>) but I am not sure, which one to chose.
I guess, that lsqr(A,b,tol,maxit,M1,M2,x0) might be a good choice (just maybe ;-) ) but now I am wondering how to chose an appropriate preconditioning M1 and M2. As mentioned before, I have to solve this problem a couple of times, therefore I think that I should be able to provide an good guess on x0 the second time a try to solve this problem - but I am not really sure how to do this... Plus: when I use lsqr or bicq without any changes, the results looks like crap ;-)
You might have figured, that I am more of an engineer than a mathematician, therefore I'm not really sure what to do.
It would be so great, if you could give me decent advice :-)
Best regards Nils

5 件のコメント
John D'Errico
2014 年 3 月 10 日
Patrik - pinv would be terribly slow compared to backslash.
Nils
2014 年 3 月 10 日
You should try wikipedia instead, matlabs function svd, does a singular value decomposition. It does not invert matrices. However, this can be used as a tool for matrix inversion. I know that this is nothing automatical or even simple, but if matlabs functions does not work, this may be necessary. I am not sure it works, but it is worth a try. The thing is that one application of svd is that its relation to pseudo inverses makes it possible to split up the matrix and calculate the inverse of all the non-zero parts.
@John D'Errico, are you sure pinv is still slower if the matrix is sparse?
Nils
2014 年 3 月 11 日
回答 (2 件)
Paul
2014 年 3 月 10 日
Did you try defining A and b as sparse? So:
A=sparse(A);
b=sparse(b);
x=A\b;
Nils
2014 年 3 月 10 日
0 投票
6 件のコメント
See http://www.mathworks.nl/help/matlab/math/sparse-matrix-operations.html#f6-9169 . If your matrix A is symmetric I guess symmlq should be faster.
Nils
2014 年 3 月 10 日
I should've seen it's not symmetric from the figure, my bad. I don't know how much faster it would be. But what's the result if you use lsqr, so:
x = lsqr(A,b,TOL,MAXIT,[],[],x0)
where TOL and MAXIT are the tolerance, and maximum number of iterations respectively. You don't have to specify them (put [] there in that case like I did for M1 and M2). x0 is your initial guess. You can use x as the x0 of the next time by doing:
for i=1:times_you_needtosolve
blabla; % put your statements that define A and b here
x{i} = lsqr(A,b,TOL,MAXIT,[],[],x0)
x0 = x{i};
end
x{i} corresponds to the solution for the ith problem. You can also put all solutions in a matrix by replacing it with x(:,i) and doing the same for the x0 = ... line.
Nils
2014 年 3 月 10 日
Paul
2014 年 3 月 10 日
Well, a solution may not exist. Are you sure you need to solve x=A\b, because afaik an upwind scheme for solving differential equations means that you use values from the previous time step and at the grid points around the point you consider to calculate the new value. What you basically do is :
x_new = A * x_old
Where A is the matrix which defines the points you use for the calculation at each point. So you really don't need to find the inverse since this is just a simple matrix multiplication.
カテゴリ
ヘルプ センター および File Exchange で Linear Algebra についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
