Reduced row echelon form: Difference between revisions

Content added Content deleted
(→‎{{header|D}}: add implementation)
m (Move pseudocode here from WP)
Line 1: Line 1:
{{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). Pseudocode found [[wp:Rref#Pseudocode|here]] may be used, or built-in functions may be used.
{{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). Built-in functions or this pseudocode (from Wikipedia) may be used:
'''function''' ToReducedRowEchelonForm(Matrix M) '''is'''
''lead'' := 0
''rowCount'' := the number of rows in M
''columnCount'' := the number of columns in M
'''for''' 0 &le; ''r'' < ''rowCount'' '''do'''
'''if''' ''columnCount'' &le; ''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 &le; ''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:
For testing purposes, the RREF of this matrix: