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

#1 Write matlab function that takes a matrix, a row number, and a scalar as its

ID: 3568276 • Letter: #

Question

#1 Write matlab function that takes a matrix, a row number, and a scalar as its arguments and multiplies each element of the row by the scalar and returns the updated matrix

#2 Write a matlab function that takes a matrix, two row numbers, and a scalar as arguments and returns a matrix with a linear combination of the rows. For example, if the rows were (i) and (j) and the scalar (s), each element of row j would become sa_ij+a_jk, where k is cols 1 through the number of cols in the matrix.

#3 Write a matlab function that takes a matrix, a row number, and a column number. Beginning with the row number passed, scan down the column passed and return the row number that contains the largest absolute value in the column.

Explanation / Answer

1)

function M = m_matrix(M,row,scalar)

[x y] = size(M);

for i = 1 : y

      M(row,i) = M(row,i)*scalar;

end

return;

Executing the function:

Matrix M = [1 2 3; 4 5 6; 7 8 9]

row = 2 and scalar = 1

Output matrix: 1 2 3

                        4 5 6

                        7 8 9

2)

function M = m_matrix(M,row1,row2,scalar)

[x y] = size(M);

for i = 1 : y

            M(row2,i) = M(row1,i)*scalar + M(row2,i);

end

return;

Executing the function:

Matrix M = [1 2 3; 4 5 6; 7 8 9]

row = 2 and scalar = -1

Output matrix: 1 2 3

                        3 3 3

                        7 8 9

3)

function M = m_matrix(M,row,col)

[x y] = size(M);

M(row,i) = max(abs(row));

end

return;

Executing the function:

Matrix M = [1 2 3; 4 5 -6; 7 8 9]

row = 2 and col = 2

Output = 6