フィルターのクリア

alternatives to create a huge 9 diagonal matrix to spdiags

3 ビュー (過去 30 日間)
Maider Marin
Maider Marin 2011 年 3 月 16 日
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 件のコメント
David Kusnirak
David Kusnirak 2013 年 4 月 22 日
Nothing new here? I'm bearing the same problem.

サインインしてコメントする。

回答 (1 件)

Jan
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 件のコメント
Maider Marin
Maider Marin 2011 年 3 月 16 日
It takes almost the same time...I think I just found matlab boundary...I will try to avoid to create the coefficient matrix by programming PCG on my own. Thanks
Jan
Jan 2011 年 3 月 16 日
What a pitty.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by