Math, asked by mohdaamir29, 9 months ago

write a function called trio that takes two positive integers n and m .The function returns s 3n - by -m matrix called T.The top third of T( an n by m)is all 1s and middle third is all 2s while the bottom third is all 3s . ​

Answers

Answered by SaI20065
19

A N S W E R

PLS MARK ME AS BRAINLIST PLS MATE

Answered by shahriyer15promi
6

Answer:

%created function in editor

function M = trio(n,m)

created_matrix = zeros(3*n,m);

created_matrix(1 : n, 1 : m) = 1;

created_matrix(1+n : n+n , 1 : m) = 2;

created_matrix(1+2*n : n+2*n , 1 : m) = 3;

M = created_matrix;

end

% executing the function in command window

T = trio(2,4)

% answer

T =  

     1     1     1     1

     1     1     1     1

    2     2     2     2

    2     2     2     2

    3     3     3     3

    3     3     3     3

Step-by-step explanation:

% line 1:  this is my function which takes two positive integers as input (n, m)  and return an output matrix

function M = trio(n,m)

% line 2: I have created a matrix of order (3*n by m) off all zeros initially

created_matrix = zeros(3*n,m);

% line 3: 1st one-third of the matrix will be assigned as 1 ; here n will be multiplied 3 times which means (n+n+n) so 1st one-third will be simply 1:n number of rows and 1:m are all columns.

created_matrix(1:n, 1:m) = 1;

% line 4: 2nd one-third of the matrix will be assigned as 2. So 2nd one-third will be simply 1+n : n+n  number of rows (means adding n with the 1st one-third of rows. it will be automatically be the 2nd one-third rows);  and 1:m are all columns as usually.

created_matrix(1+n : n+n , 1 : m) = 2;

% line 5:  final one-third of the matrix will be assigned as 3.

created_matrix(1+2*n : n+2*n , 1 : m) = 3;

% line 6: its for my own styling I like to put my matrix into another variable which will act as output matrix of main function.

M = created_matrix;

% line 7: its end of the function

end

Similar questions