i want to fill in a 100×100 matrix using a nested for loop. However for each ’i’ row there will only be 3 ‘j’ columns with nonzero numbers. Also i want leave the first and last row all zeros. This is what ive tried before and its not working. what am i doing wrong?
A = zeros(100,100);h = 1;for i = 2:99; for j = 2:99; A(i, j+1) = ((1/h) + i); A(i, j) = (-2/h); A(i, j-1) = ((1/h) - i); endend%so after one iteration i would have the values at the given indices
% %A(2,3) = 3
%A(2,2)=-2
%A(2,1)=-1
Best Answer