Project 1 In this project youll write a MATLAB program that

Project 1

In this project, you’ll write a MATLAB program that converts a matrix to row echelon form. A code that does that would need to do the following:

1. Find the first nonzero column, call it j.
2. Find the first nonzero entry in column j, call its position (i, j).
3. Swap the top row and row i.
4. Divide the new top row by its leading entry.
5. For each row k from the second-from-the-top to the nth row, subtract the

value of the (k, j)-entry times the top row from row k.
6. Repeat steps 1 through 4 for the submatrix produced by deleting the top row

of the previous matrix.

Extra credit: Add onto the program so that it also converts the row echelon form

matrix to reduced row echelon form.

Solution

function m = ref(a) % Script for Row-Echelon Form % ----written by---------------------------- % Muhammad Rafiullah Arain % Department of Mathematics % COMSATS Institute of Information technology - Lahore % Pakistan. % ------------------------------------------ % ref(a) defination and use % ------------------------------------------ % a is nxn matrix % Example % >> a=[1 2 3 5; 2 4 5 6; 7 3 7 2; 2 4 1 8] % >> ref(a) % result show a row-echelon-form if length(a(1,:)) ~= length(a(:,1)) error(\'Matrix is not square nxn or wrong number of input arguments\') end n=length(a(1,:)); j=1; for i = 1:n-1 if (i==j) if (a(i,j)==0) c = a(i,:); a(i,:)= a(i+1,:); a(i+1,:) = c; end a(i,:)= (1/a(i,j))* a(i,:); for k=i+1:n a(k,:)=(-a(k,j)* a(i,:)) + a(k,:); end end j=j+1; end a(n,:)= (1/a(n,n))* a(n,:); m=a; end
Project 1 In this project, you’ll write a MATLAB program that converts a matrix to row echelon form. A code that does that would need to do the following: 1. Fi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site