Skip to content

Instantly share code, notes, and snippets.

@lettergram
Created March 19, 2015 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lettergram/5e1c028b668e006221a7 to your computer and use it in GitHub Desktop.
Save lettergram/5e1c028b668e006221a7 to your computer and use it in GitHub Desktop.
import numpy as np
from scipy.linalg import solve
def gauss(A, b, x, n):
L = np.tril(A)
U = A - L
for i in range(n):
x = np.dot(np.linalg.inv(L), b - np.dot(U, x))
print str(i).zfill(3),
print(x)
return x
'''___MAIN___'''
A = np.array([[4.0, -2.0, 1.0], [1.0, -3.0, 2.0], [-1.0, 2.0, 6.0]])
b = [1.0, 2.0, 3.0]
x = [1, 1, 1]
n = 20
print gauss(A, b, x, n)
print solve(A, b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment