Created
December 28, 2015 22:06
-
-
Save psqq/5f2a08c914cf131cf937 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fractions import Fraction | |
a = [[1, 5, 1, 0, 0], | |
[3, 2, 0, 1, 0], | |
[2, 4, 0, 0, 1]] | |
b = [10, 12, 10] | |
c = [2, 3, 0, 0, 0] | |
f = [-2, -3, 0, 0, 0] | |
a = [[Fraction(a[i][j]) for j in range(len(a[i]))] for i in range(len(a))] | |
b = [Fraction(b[i]) for i in range(len(b))] | |
def pl(a, msg="", ln=True): | |
if msg: print( msg) | |
for i in range(len(a)): print("%5s" % a[i], end="") | |
if ln: print() | |
def p(a, msg): | |
if msg: print(msg) | |
if type(a[0]) != list: | |
pl(a) | |
return | |
for i in range(len(a)): | |
pl(a[i]) | |
def f(a, b, k, s): | |
resa = [[a[i][j] for j in range(len(a[i]))] for i in range(len(a))] | |
resb = [b[i] for i in range(len(b))] | |
for i in range(len(a)): | |
for j in range(len(a[i])): | |
if i == k: resa[i][j] = a[i][j] / a[k][s] | |
else: resa[i][j] = a[i][j] - a[k][j]*a[i][s]/a[k][s] | |
for i in range(len(b)): | |
if i == k: resb[i] = b[i]/a[k][s] | |
else: resb[i] = b[i] - b[k]*a[i][s]/a[k][s] | |
return resa, resb | |
p(a, "a") | |
p(b, "b") | |
iters = [[a, b]] | |
def ite(i, s, k): | |
na, nb = f(iters[i-1][0], iters[i-1][1], s, k) | |
iters.append([na, nb]) | |
p(na, "a" + str(i)) | |
p(nb, "b" + str(i)) | |
ite(1, 0, 1) | |
ite(2, 0, 1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment