In: Advanced Math
Write a Matlab function for a matrix that takes in a matrix in echelon form and will return the row canonical form. The function cannot use rref, or any other matlab built in functions.
SOLUTION:
Given that data Write a Matlab function for a matrix that takes in a matrix in echelon form and will return the row canonical form. The function cannot use rref, or any other matlab built in functions.
So the matlab function is given below
function To Reduced Row Echelon Form(Matrix M) is
lead := 0
rowCount := the number of rows in M
columnCount := the number of columns in M
for 0 ≤ r < rowCount do
if columnCount ≤ lead then
stop
end if
i = r
while M[i, lead] = 0 do
i = i + 1
if rowCount = i then
i = r
lead = lead + 1
if columnCount = lead then
stop
end if
end if
end while
Swap rows i and r
If M[r, lead] is not 0 divide row r by M[r, lead]
for 0 ≤ i < rowCount do
if i ≠ r do
Subtract M[i, lead] multiplied by row r from row i
end if
end for
lead = lead + 1
end for
end function