import numpy as np
def Jacobi(A, b, iter_n, initial_guess=0):
n = len(A)
D = np.diag(A)
R = A - np.diag(D)
x_i = initial_guess * np.ones(n)
for i in range(iter_n):
print('x_',i,'=',x_i)
x_i = (b - R.dot(x_i)) / D
return x_i
def A_ij(n):
A = np.empty((n, n))
for i in range(n):
A[i, i] = 2
for i in range(n-1):
A[i,i+1]=A[i+1,i]=1
return A
def b_i(n):
b=np.empty(n)
b[0]=1
b[n-1]=-1
return b
def x0(n):
return np.zeros(n)
print(Jacobi(A,b,100,x0))