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

4.Creating Functions (2 points) Matlab has some built-in functions that we have

ID: 3724235 • Letter: 4

Question

4.Creating Functions (2 points) Matlab has some built-in functions that we have already used, such as sin(x), plot, etc. Type help function and read the documentation and examples on how to create functions in Matlab. Create a function called custom matrix.m that take two parameters, the matrix number of rows (i) and columns (j). The output of your function should be a matrix called SM. The elements of SM(m, n) where m-= n should be (m*n). The elements of SM(m,n) where m > n should be (m). The elements of SM(m,n) where n > m should be n. An example of your function output when i-4 and j- 4 is provided below. 1 2 3 4 2 4 3 4 3 3 9 4 4 4 4 16

Explanation / Answer

Matlab code :

function SM = customer_matrix(m,n)
SM=ones(m,n);
if m==n
for i=1:m
for j=1:m
SM(i,j)=i.*j;
end
end
elseif m<n
SM=n.*SM;
else
SM =m.*SM;
end
end

>> customer_matrix(2,5)

ans =

5 5 5 5 5
5 5 5 5 5

>> customer_matrix(10,5)

ans =

10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10
10 10 10 10 10

>> customer_matrix(5,5)

ans =

1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25

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