tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,35 @@
|
|||
def ToReducedRowEchelonForm( M):
|
||||
if not M: return
|
||||
lead = 0
|
||||
rowCount = len(M)
|
||||
columnCount = len(M[0])
|
||||
for r in range(rowCount):
|
||||
if lead >= columnCount:
|
||||
return
|
||||
i = r
|
||||
while M[i][lead] == 0:
|
||||
i += 1
|
||||
if i == rowCount:
|
||||
i = r
|
||||
lead += 1
|
||||
if columnCount == lead:
|
||||
return
|
||||
M[i],M[r] = M[r],M[i]
|
||||
lv = M[r][lead]
|
||||
M[r] = [ mrx / lv for mrx in M[r]]
|
||||
for i in range(rowCount):
|
||||
if i != r:
|
||||
lv = M[i][lead]
|
||||
M[i] = [ iv - lv*rv for rv,iv in zip(M[r],M[i])]
|
||||
lead += 1
|
||||
|
||||
|
||||
mtx = [
|
||||
[ 1, 2, -1, -4],
|
||||
[ 2, 3, -1, -11],
|
||||
[-2, 0, -3, 22],]
|
||||
|
||||
ToReducedRowEchelonForm( mtx )
|
||||
|
||||
for rw in mtx:
|
||||
print ', '.join( (str(rv) for rv in rw) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue