Commit b86e7475 authored by Kittisak Maneewong's avatar Kittisak Maneewong

ส่งงาน week05

parent 8c0f6fb2
......@@ -3,8 +3,8 @@
def ge(A,b):
import numpy as np
A=np.array(A)
b=np.array(b)
A=np.array(A,float)
b=np.array(b,float)
n = len(b)
for k in range(0, n - 1):
for i in range(k + 1, n):
......@@ -14,8 +14,8 @@ def ge(A,b):
b[i] = b[i] - lam * b[k]
# back
x = b.copy()
for k in range(n - 1, -1, -1):
x[k] = (b[k] - np.dot(A[k, k + 1:n], x[k + 1:n])) / A[k, k]
for k in range(n-1,-1,-1):
x[k] = (b[k]-np.dot(A[k,k+1:n],x[k+1:n]))/A[k,k]
for i,x in zip(range(1,len(x)+1),x):
print("x_{} = {}".format(i,x))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment