Example #1
0
def example5():
	L, T = 1., 2
	N_x, N_t = 200, 440
	def f(x):
		return 4.*np.sin(4*np.pi*x)
	
	def g(x):
		return np.zeros(x.shape)
	
	view = [0-.1,L+.1,-5,5]
	Data = wave_1d(f,g,L,N_x,T,N_t,view)
	stride = 2
	Data = Data[0], Data[1][::stride,:]
	time_steps, wait = int(N_t/stride), 200
	
	math_animation(Data,time_steps,view,wait)
Example #2
0
def example2():
	L, T = 1., 2
	N_x, N_t = 200, 440
	m, u_0 = 20, .2
	def f(x):
		return u_0*np.exp(-m**2.*(x-1./2.)**2.)
	
	def g(x):
		return -m**2.*2.*(x-1./2.)*f(x)
	
	view = [0-.1,L+.1,-.5,.5]
	Data = wave_1d(f,g,L,N_x,T,N_t,view)
	stride = 1
	Data = Data[0], Data[1][::stride,:]
	time_steps, wait = int(N_t/stride), 4
	
	math_animation(Data,time_steps,view,wait)
Example #3
0
def example4():
	L, T = 1., 2
	N_x, N_t = 200, 440
	def f(x):
		y = np.zeros_like(x)
		y[np.where( (5.*L/11. < x) & (x < 6*L/11. ) ) ] = 1./3
		return y

	def g(x):
		return np.zeros(x.shape)
	
	view = [-.1,L+.1,-.5,.5]
	Data = wave_1d(f,g,L,N_x,T,N_t,view)
	stride = 2
	Data = Data[0], Data[1][::stride,:]
	time_steps, wait = int(N_t/stride), 80
	
	math_animation(Data,time_steps,view,wait)
Example #4
0
def example3():
	L, T = 1., 2
	N_x, N_t = 200, 440
	
	m, u_0 = 20, 1/3.
	def f(x):
		return u_0*np.exp(-m**2.*(x-1./2.)**2.)
	
	def g(x):
		return np.zeros(x.shape)
	
	view = [-.1,L+.1,-.5,.5]
	Data = wave_1d(f,g,L,N_x,T,N_t,view)
	stride = 2
	Data = Data[0], Data[1][::stride,:]
	time_steps, wait = int(N_t/stride), 80
	
	math_animation(Data,time_steps,view,wait)
Example #5
0
def example1():
	# L, T = 1., 2
	L = 1.; T = .5
	# N_x, N_t = 200, 440
	N_x, N_t = 5,5
	def f(x):
		return np.sin(2*np.pi*x) #+ 4.*np.sin(np.pi*x) + .2*np.sin(4*np.pi*x)
	
	def g(x):
		return np.zeros(x.shape)
	
	view = [0-.1,L+.1,-5,5]
	Data = wave_1d(f,g,L,N_x,T,N_t,view)
	grid, sol = Data
	plt.plot(grid,sol[-1,:],'-r',linewidth=2.)
	plt.plot(grid,-np.sin(2*np.pi*grid),'-k',linewidth=2.)
	plt.show()
	plt.clf()