using jacobi method to solve laplace equation PYTHON -


i new python , trying recreate electric potential in metal box using laplace equation , jacobi method. have written code seems work initially, getting error: indexerror: index 8 out of bounds axis 0 size 7 , can not figure out why. awesome!

from visual import* visual.graph import* import numpy np   lenx = leny = 7 delta = 2  vtop = [-1,-.67,-.33,.00,.33,.67,1] vbottom = [-1,-.67,-.33,.00,.33,.67,1] vleft = -1 vright = 1  vguess= 0  x,y = np.meshgrid(np.arange(0,lenx), np.arange(0,leny))  v = np.empty((lenx,leny)) v.fill(vguess)  v[(leny-1):,:] = vtop v [:1,:] = vbottom v[:,(lenx-1):] = vright v[:,:1] = vleft  maxit = 500  iteration in range (0,maxit):     in range(1,lenx):         j in range(1,leny-1):             v[i,j] = .25*(v[i+i][j] + v[i-1][j] + v[i][j+1] + v[i][j-1])             print v 

just quick glance @ code seems though indexing error happening @ part , can changed accordingly:

# had v[i+i][j] instead if v[i+1][j] v[i,j] = .25*(v[i+1][j] + v[i-1][j] + v[i][j+1] + v[i][j-1]) 

you added , i indexing have been out of range


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -