Kronecker Tensor Product for very large matrices
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
William Kett
am 15 Jul. 2021
Bearbeitet: Matt J
am 18 Jul. 2021
I need to build a 2D kronecker tensor product of with a size of approximately 10^6 x 10^6. The problem is that I get the following message:
%Out of memory. Type HELP MEMORY for your options.
Is there any way to get around this memory limitation? My code is posted below:
nx = 1000;ny = 1000; %Number of points along x and y
dx = 1/(nx-1);dy = 1/(ny-1); %Spacing between each point
diag_block = eye(ny-1) * (-2/dx^2-2/dy^2); %Identity Matrix of ny-1 points
diag_block = diag_block + diag(ones(ny-2,1)/dy^2,1); %
diag_block = sparse(diag_block) + sparse(diag(ones(ny-2,1)/dy^2,-1)); %
Matrix = kron(sparse(eye(nx-1)),sparse(diag_block)); %Using sparse() made this line work
Matrix = Matrix + diag(ones((nx-2) * (ny-1),1)/dx^2, ny-1); %FAILS HERE!!!
Matrix = Matrix + diag(ones((nx-2) * (ny-1),1)/dx^2, -(ny-1)); %AND HERE!!!
0 Kommentare
Akzeptierte Antwort
Matt J
am 16 Jul. 2021
Bearbeitet: Matt J
am 16 Jul. 2021
You need the matrices generated by diag() in sparse form, too. Use spdiags() instead, e.g.,
nx = 3;ny =3; dx=1; %Number of points along x and y
Qfull=diag(ones((nx-2) * (ny-1),1)/dx^2, ny-1)
Bin=[0;0;ones((nx-2) * (ny-1),1)/dx^2];
Q=spdiags(Bin,ny-1,4,4)
full(Q)
4 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Sparse 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!