Hi,
I am trying to write some code that will solve the 2D wave equation by the finite difference method, but it just returns an array full of zeros and NaN's. Not sure where I am going wrong, the code is attached so if could someone point me in the right direction I'd appreciate this.
Thanks
D
# 2D Finite Distance Wave Equation.
from pylab import *
from numpy import math

# Set up variables.
nx = 100
nz = 100
nsteps = 300
c = 4000
dt = 1**-4
h = 1
t = arange(0,nsteps,dt)

# Define source as a spike.
s = zeros(nsteps)
s[1] = 1
s[2] = 2
s[3] = 1

# Position source.
xs = 50
zs = 50
##plot(t,s)
##show()


# Set up pressure field.
p=empty([nx,nz,nsteps])

for t in range(0,nsteps-1):

    for z in range(0,nz-1):

        for x in range(0,nx-1):

            p[x,z,t] = 0



# Solve wave equation.
for t in range(2,nsteps-1):

    
    for z in range(1,nz-1):

        for x in range(2,nx-1):

            p[xs,zs,t] = s[t]

            k = (c*dt/h)**2

            p[x,z,t] = 2*p[x,z,t-1] - p[x,z,t-2] + 
k*(p[x+1,z,t-1]-4*p[x,z,t-1]+p[x-1,z,t-1]+p[x,z+1,t-1]+p[x,z-1,t-1])





    
    

    
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to