use matlab plz We want to create a special 5X5 square matrix that has ones in th
ID: 2081249 • Letter: U
Question
use matlab plz
We want to create a special 5X5 square matrix that has ones in the first row and first column, and whose remaining elements are the sum of two elements, the element are above and the element to the left, if the sum is less than 20. Otherwise, the element is the maximum of those two element values. Develop an M-file able to generate this matrix. First of all, create 5-by-5 matrix of ones and then try to change elements to the proper values. the final answer should be as bellow; when you get the bellow answer, raise your hand to get your mark. A= [1 1 1 1 1 1 2 3 4 5 1 3 6 10 15 1 4 10 10 15 1 5 15 15 15]Explanation / Answer
clc;
clear all;
A = ones(5,5);
for i=1:5
for j=1:5
if i>1 && j>1%only for column and row number greater than 1
if (A(i-1,j)+A(i,j-1))<20%if sum is less than 20
A(i,j) = A(i-1,j)+A(i,j-1);
else
A(i,j) = max( A(i-1,j),A(i,j-1));%if sum greater than 20
end
end
end
end
disp(A);
Command window output:
>> A
A =
1 1 1 1 1
1 2 3 4 5
1 3 6 10 15
1 4 10 10 15
1 5 15 15 15
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.