def solve(Q, R, b): y = multiply(transpose(Q), b) print_matrix(R, round_elem=True) C = append_column(R, y) x = [backward_right(C, i) for i in xrange(len(C) - 1, -1, -1)] x.reverse() return x
def solve(A, b): S = append_column(A, b) for i in xrange(len(S)): print("Choosing main for iteration #{}".format(i)) choose_main(S, i) gk.forward(S, i) roots = [] for i in xrange(len(S) - 1, -1, -1): roots.append(gk.backward_right(S, i)) roots.reverse() return roots
def solve(A, b): n = len(A) L, U = lu(A) y = [] Lb = append_column(L, b) for row in xrange(n): y.append(gk.backward_left(Lb, row)) Uy = append_column(U, [[e] for e in y]) x = [] for row in xrange(n - 1, -1, -1): x.append(gk.backward_right(Uy, row)) x.reverse() return x
def main(): from constants import A2, b2 n = len(A2) L, U = lu(A2) y = [] Lb = gk.append_column(L, b2) for row in xrange(n): y.append(gk.backward_left(Lb, row)) Uy = gk.append_column(U, [[e] for e in y]) x = [] for row in xrange(n - 1, -1, -1): x.append(gk.backward_right(Uy, row)) x.reverse() check(A2, x, b2)
def solve(A, b): n = len(A) U = getU(A) gk.print_matrix(U) Ut = transpose(U) y = [] Utb = gk.append_column(Ut, b) for row in xrange(n): y.append(gk.backward_left(Utb, row)) print(y) Uy = gk.append_column(U, [[e] for e in y]) x = [] for row in xrange(n - 1, -1, -1): x.append(gk.backward_right(Uy, row)) x.reverse() return x, U
A2 = m.multiply(P, A) for j in xrange(n): L[j][j] = 1.0 for i in xrange(j + 1): s1 = sum(U[k][j] * L[i][k] for k in xrange(i)) U[i][j] = A2[i][j] - s1 for i in xrange(j, n): s2 = sum(U[k][j] * L[i][k] for k in xrange(j)) L[i][j] = (A2[i][j] - s2) / U[j][j] return L, U, P from var30_constants import A1 as A, B1 as B L, U, P = lu(A) D = m.multiply(P, B) C = [] for i in xrange(len(L)): C.append(L[i] + [D[i][0]]) m.print_matrix(C) y = m.transpose([[backward_left(C, i) for i in xrange(len(C))]]) C = [] for i in xrange(len(U)): C.append(U[i] + [y[i][0]]) x = [backward_right(C, i) for i in xrange(len(C) - 1, -1, -1)] x.reverse() m.print_matrix(m.multiply(A, m.transpose(x))) m.print_matrix((get_inv(L, U)))