alternatives to create a huge 9 diagonal matrix to spdiags
2 ビュー (過去 30 日間)
古いコメントを表示
I have a problem I am working with a 9 diagonal linear system, what I am doing is finding the vectors of each diagonal, let me called Ai and then using spdiags function to form the coeficient matrix but my matrix is huge somenthing like 1 million x 1 million and spdiags is taking like 1.5 h just for doing the matrix is there any better way to do this. I would appraciate any help. Let me give you some code
[row,col,bands]=size(I)
Diag=[A1 A2 A3 A4 A5 A6 A7 A8 A9]; %Ai: col vector of ith diagonal
n=length(A5);%A5 main diagonal
indx=[-row-1;-row;-row+1;-1;0;1;row-1;row;row+1];
A=spdiags(Diag,indx,n,n)
1 件のコメント
回答 (1 件)
Jan
2011 年 3 月 16 日
Perhaps this helps:
[row,col,bands] = size(I)
Diag = [A1 A2 A3 A4 A5 A6 A7 A8 A9];
n = length(A5);
indx = [-row-1;-row;-row+1;-1;0;1;row-1;row;row+1];
A = spalloc(numel(Diag), n, n);
for i = 1:9
A = spdiags(Diag(:, i), indx(i), A);
end
All A1 to A9 have the same length, correct? I've reserved more memory for A than necessary. I assume, you can fix this according to the value of "row".
Does this create the wanted result? If so, I'm not sure, why SPDIAGS is so much slower when inserting all diagonals together.
4 件のコメント
参考
カテゴリ
Help Center および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!