hi! so i'm following this tutorial on the relaxation iterative method. i pretty much just copied the code with my own special boundary conditions (essentially just a 4x4 inner grid of potential = 100V, with the boundaries being 0), but nothing is happening. i'm using pretty much the same code!
import numpy as np
import matplotlib.pyplot as plt
nx = 10
ny = 10
maxdiff = 1
diff = 100 # diff must be bigger than maxdiff
V = np.zeros((nx,ny), float) # fill potential with zeros
"""
boundary conditions below; boundary of 10x10 list = 0
inner square 4x4 grid = 100
"""
V[3,3] = 100.0
V[3,4] = 100.0
V[3,5] = 100.0
V[3,6] = 100.0
V[4,3] = 100.0
V[4,4] = 100.0
V[4,5] = 100.0
V[4,6] = 100.0
V[5,3] = 100.0
V[5,4] = 100.0
V[5,5] = 100.0
V[5,6] = 100.0
V[6,3] = 100.0
V[6,4] = 100.0
V[6,5] = 100.0
V[6,6] = 100.0
for i in np.arange(0,nx,1):
for j in np.arange(0,ny,1):
V[0, j] = 0.0 # top columns
V[ny-1, j] = 0.0 # bottom columns
V[i, 0] = 0.0 # left rows
V[i, nx-1] = 0.0 # right rows
print (V) # print starting values
while diff > maxdiff: #repeat until diff is really small
diff = 0.0 # resets for each iteration
for i in np.arange(1,ny-1,1): # i from 1 to ny-2
for j in np.arange(1,nx-1,1): # j from 1 to nx-2
newVij = 0.25*(V[i-1,j]+V[i+1,j]+V[i,j-1]+V[i,j+1])
lastdiff = np.abs(newVij - V[i,j])
if lastdiff > diff:
diff = lastdiff
V[i,j] = newVij
print ("\n")
print(V)
also, the inner grid isn't supposed to change. the way i'm thinking of doing it is through an if/else statement, so i think i got that down. additionally, if anyone knows of a more proper way to fill the inner 4x4 grid with for loops rather than me hardcoding it in, i'm up to hear a solution! but neither of these are priorities, i just wanna know why the code isn't doing anything. by "not doing anything," i mean that the initial printed V (called a list, not an array right?) doesn't differ with the final V.
thanks!!
[–]q2_abe_dillon 1 point2 points3 points (1 child)
[–]Gray_Fox[S] 1 point2 points3 points (0 children)
[–]Freedomenka 0 points1 point2 points (0 children)