In: Computer Science
Make a 20 by 20 matrix in which diagonal elements are 21, 22, 23, 24 … 40 and elements below the diagnol are ij = 2(i 2 j 2 ) and elements above the diagnol are 4×(i+j) Note: You must use if, elseif, else, end or/and if, end or/and if, else, end commands in MATLAB.
Thanks for the question, For the elements below diagonal I didnt understand the expression ij = 2(i 2 j 2 ), I have assumed it to as 2 *(i*i + j*j); If this needs to be changed please let me know in comments and I will update it.
========================================================================
matrix = zeros(20,20);
for i = 1: 20
for j = 1: 20
if i==j
matrix(i,j) = 20 +i;
elseif i>j
matrix(i,j) = 2*(i^2+j^2);
else
matrix(i,j) = 4*(i+j);
end
end
end
matrix
=========================================================================