Rectangular Matrix Row Echelon Form

A=[1,2,1,3,3;2,4,0,4,4;1,2,3,5,5;2,4,0,4,7]
[n1,n2]=size(A); % # of rows and columns
p = (1:n1)'; % # each row in the matrix to pivot if necessary
for k = 1:n1-1 % Repeat the loop based on 1 - #rows
[r,m] = max(abs(A(k:n1,k))) % r is the value of the max in the kth col and m is the % matrix location
m = m+k-1 %Previous max matrix location plus the next 'k' step in the matrix
if r~=0 %Checks to see if the col is zero break; end end
if (m~=k) %Checks to see if the max vector location equals the the next location %step in the matrix. If not the switch the rows. A([k m],:) = A([m,k],:) p([k m]) = p([m k]) end
i = k+1:n1; %Count for the next row
C(i,k) = A(i,k)/A(k,k) %Storing the multipliers for the kth col in Matrix C
j = k:n2 %Counting columns
A(i,j) = A(i,j)-C(i,k)*A(k,j) %Using the multiplier to complete forward elimination
Please see the matlab code that I wrote above, it did not complete the rectangular matrix in row echelon form. It only completed one cycle, I am having difficulty telling it to skip the zero column and check for the max in the adjacent column and pivot if necessary. It seems to stop when it gets to the zero column and not move on to check the next column. Can you please help?
Your help is greatly appreciated.
Thank you,
Addanis

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by