dx = 0.1 dy = 0.1 Nx = int(1 + (Lx/dx)) Ny = int(1 + (Ly/dy)) nx = Nx-2 ny = Ny-2 d2dx = 1/(dx*dx) u = np.zeros(Nx*Ny) f = np.zeros(Nx*Ny) i = 0 for j in range(Ny): u[i+j*Nx] = 1 u = pde.jacobi(u,f,dx,Nx,Ny,1000) u_int = np.zeros(nx*ny) for j in range(ny): for i in range(nx): u_int[i+j*nx] = u[(i+1) + (j+1)*Nx] u_plot = np.zeros([Nx,Ny]) for j in range(Ny): for i in range(Nx): u_plot[i,j] = u[i+j*Nx] x = np.zeros([Nx+1,Ny+1]) y = np.zeros([Nx+1,Ny+1]) for j in range(Ny+1): for i in range(Nx+1):
f[i + j*Nx] = 1 # boundary conditions for j in range(Ny): i = 0 T[i+j*Nx] = 1 i = Nx-1 T[i+j*Nx] = 0 for i in range(Nx): j = 0 T[i+j*Nx] = 0 j = Ny-1 T[i+j*Nx] = 0 # Jacobi iteration T = pde.jacobi(T,f,dx,Nx,Ny,1000) # check error # (build matrix) nx = Nx - 2 ny = Ny - 2 A = np.zeros([nx*ny,nx*ny]) for q in range(nx*ny): for p in range(nx*ny): if p == q: A[p,q] = -4*d2dx2 elif p == q-1: A[p,q] = 1*d2dx2 elif p == q+1: A[p,q] = 1*d2dx2 elif p == q-nx: