Write a function named swap to swap two rows in a matrix You

Write a function, named swap, to swap two rows in a matrix. You will pass the matrix and two row numbers to exchange. Write a function that takes a matrix, a row number and a scalar as arguments (inputs) and multiplies each element of the row of the matrix by the scalar returning (outputs) the updated matrix. Write a 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 passed to the function were i and j and the scalar was alpha, each element of row j would become alpha a_ik + a_jk, where k represents columns 1 through the number of columns in the matrix. Write a function that takes a matrix, a row number and a column number. Compare the entry in the row and column inputted by the user to the other entries below it in the same column. Then, return the row number that contains the largest absolute value in the column. For example, if your matrix is [1 9 4 5 11 -2 3 0 0 -6 5 4 3 5 7 -3] and you pass row 2, column 2, the function should return 3. Row 3 has the largest absolute value in column 2 including and below row 2.

Solution

1-Following is the program which 3 argument (1 matrix and 2 elements which you want to swap)

function matrix = swap(matrix,x,y)
% Swaps the contents in matrix of elements x and y
if nargin ~= 3
error(\'Must be called with 3 arguments.\');
end
if length(x) == 2
x = sub2ind(size(matrix),x(1),y(2));
elseif length(x) ~= 1
error(\'Enter an index or subscript for the location of x=\');
end
if length(y) == 2
y = sub2ind(size(matrix),y(1),x(2));
elseif length(y) ~= 1
error(\'Enter an index or subscript for the location of y=\');
end

tmp = matrix(x);
matrix(x) = matrix(y);
matrix(y) = tmp;
clear tmp;

THANKYOU!

FOR OTHER QUESTIONS PLEASE POST THESE QUESTIONS AS A SEPRATE QUESTIONS

 Write a function, named swap, to swap two rows in a matrix. You will pass the matrix and two row numbers to exchange. Write a function that takes a matrix, a r

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site