In: Computer Science
Make a 20 by 20 matrix in which diagonal elements are 2, 5, 8, 11 ... 59 and the first column is 21,22,23,24 ... 40 whereas the rest of the elements of the matrix are 9.
Note: you must if, elseif, else, end or/and if, end or/and if, else, end commands in MATLAB.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.
Thank You!
===========================================================================
matrix = zeros(20,20);
for i = 1: 20
for j = 1: 20
if j==1
matrix(i,j) = 2*i;
elseif i==1 & j==1
matrix(i,j) = 2;
elseif i==j
matrix(i,j) = matrix(i-1,j-1)+3;
else
matrix(i,j) = 1;
end
end
end
matrix
=====================================================================