How can I generate 3 sparse matrices using 2 for loops?

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (0)

Categorie

Scopri di più su Operating on Diagonal Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by