Anonymous user
Reduced row echelon form: Difference between revisions
m
Move pseudocode here from WP
(→{{header|D}}: add implementation) |
m (Move pseudocode here from WP) |
||
Line 1:
{{wikipedia|Rref#Pseudocode}}{{task|Matrices}}Show how to compute the '''reduced row echelon form''' (a.k.a. '''row canonical form''') of a matrix. The matrix can be stored in any datatype that is convenient (for most languages, this will probably be a two-dimensional array).
'''function''' ToReducedRowEchelonForm(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''
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'''
For testing purposes, the RREF of this matrix:
|