Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

EXERCISE 4: WRITING ACODE (FUNCTION) AND RUNNING IT PLEASE REVIEW OPERATORS AND

ID: 3781694 • Letter: E

Question

EXERCISE 4: WRITING ACODE (FUNCTION) AND RUNNING IT PLEASE REVIEW OPERATORS AND ELEMENTARY OPERATIONS AT http://www.m matlab ators-and-eleme erations html In this exercise, you will create, if possible, an m by n matrix. AT such that, an (i, j)- entry of the matrix A. AGiaj), is the sum of the indexes i andj, where i nuns from 1 to m and j runs from 1 to n. You can use for loop in order to construct the matrix A, given m and n. To decide whether A can be created, you will check in your code if the given variables m and n are integer. You can use the conditional statement "if else" (see for help h www.mathworks.com/ht matlab/refif html) and a MATLAB built-in function such as mod, floor, fix. If both m and n are integer, proceed to the calculation of the entries of the matrix A. If not, the outputs have to be A [JCA is an empty matrix) followed by the comment "Error in using sums: both m and n must be integer" Please follow the steps outlined below: Create the function in MATLAB A-sums (m, n **Type the function in your diary file by using command type sums Run the function A sums m, n on the following sets of variables Note: Start each part (a), (b), (c, or (d) with then input the variables m and n, and run the function. For example (a) (Hit "Enter") m 6.5, na 4 Hit "Enter") 6.5 A sums (m,n) (Hit "Enter (a) m 6.5, 4 (b) m. 1.6 (d) m 3, n 3 Create a new function in MATLAB that switches rows with columns in a matrix A -switches A) that is, BG,t) A(ij) (i 1 m, 1:n) Type the function in your diary file. Run the function B switches (A on the output matrices in parts (c)-Gd.

Explanation / Answer

% matlab code

function A = sums(m,n)
    if(mod(m,1) != 0 || mod(n,1) != 0)
        disp("Errors in using sums: both m and n must be inetger ");
        quit
    end
  
    for i=1:m
        for j=1:n
            A(i,j) = i+j;
        end
    end
end

function B = switches(A,m,n)
     for i=1:m
        for j=1:n
            B(j,i) = A(i,j);
        end
    end
end


m = 6.5;
n = 4;
A = sums(m,n);
disp("Matrix A: ");
disp(A);
B = switches(A,m,n);
disp(" Matrix B: ")
disp(B);
#output: Errors in using sums: both m and n must be inetger


m = 5;
n = 1.6;
A = sums(m,n);
disp("Matrix A: ");
disp(A);
B = switches(A,m,n);
disp(" Matrix B: ")
disp(B);
#output: Errors in using sums: both m and n must be inetger


m = 3;
n = 4;
A = sums(m,n);
disp("Matrix A: ");
disp(A);
B = switches(A,m,n);
disp(" Matrix B: ")
disp(B);

%{
output:

Matrix A:
   2   3   4   5
   3   4   5   6
   4   5   6   7

Matrix B:
   2   3   4
   3   4   5
   4   5   6
   5   6   7
%}

m = 3;
n = 3;
A = sums(m,n);
disp("Matrix A: ");
disp(A);
disp(" Matrix B: ")
B = switches(A,m,n);
disp(B);

%{
output:

Matrix A:
   2   3   4
   3   4   5
   4   5   6

Matrix B:
   2   3   4
   3   4   5
   4   5   6
%}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote