Using matlab notation, use loops to create matrix B.. in which the value of each
ID: 3860859 • Letter: U
Question
Using matlab notation, use loops to create matrix B.. in which the value of each element is the corresponding value in matrix A divided by the sum of its indices (the row number and column number of the element). For example, value of element (1,1) in B matrix is 10/(1 + 1) = 5.
Problem 1: (10 pts) 10 0 -5 -1 0 1 5 3 5 0 -1 -1 1 7 7 4 6 9 -2 2 3 8 Use loops to create matrix B in which the value of each element is the corresponding value in matrix A divided by the sum of its indices (the row number and column number of the element). For example, value of element (1,1) in B matrix is 10/(1 1) 5Explanation / Answer
%matlab code
A = [10 0 -5 -1 0 1; 5 3 5 0 -1 -1; -3 -1 7 3 -7 4; 6 9 -3 3 -3 8];
[n m] = size(A);
B = zeros(n,m);
for i=1:n
for j=1:m
% matrix A divided by the sum of its indices (the row number and column number of the element
B(i,j) = A(i,j)/(i+j);
end
end
disp(B);
%{
output:
5.00000 0.00000 -1.25000 -0.20000 0.00000 0.14286
1.66667 0.75000 1.00000 0.00000 -0.14286 -0.12500
-0.75000 -0.20000 1.16667 0.42857 -0.87500 0.44444
1.20000 1.50000 -0.42857 0.37500 -0.33333 0.80000
%}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.