How can I generate 3 sparse matrices using 2 for loops?
2 次查看(过去 30 天)
显示 更早的评论
i'm trying to generate 3 tridiagonal sparse matrices using 2 for loops. The first for loop for n=1:3, refers to the number of variables, where n is variable 1. Each variable has 23 values associated with it and the second for loop cycles through this to create the diagonal. The length of the diagonal is 23, the super and sub diagonal have 22 values. So I need to basically create 3 matrices by creating a generalized for loop. The code is:
M=zeros(23); % empty 23 by 23 matrix
n=1; k=1; % n=1; k=1; starts the counter
z=ones(1,22); % the super-diagonal are just ones
for n=1:3;
for k=1:23;
M{n}=gallery('tridiag',output(n,k:22),-phi(n,k),z);
end
end % code
end
To provide clarity, i'm trying to generate a code that describe, in a general format the matrix shown in https://www.youtube.com/watch?v=wLIJPrNNwqk at 10:57, where all the u values are 1, and d and L values depend on the variable. So i would need 3 matrices.
I feel like i'm close but i keep getting an error saying that the dimension of vector arguments are incorrect. Any ideas?
Thanks.
0 个评论
回答(0 个)
另请参阅
类别
在 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!