alternatives to create a huge 9 diagonal matrix to spdiags
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Antworten (1)
Jan
am 16 Mär. 2011
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 Kommentare
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!