Exercise_13 Motion of a Realistic String

Backgroud

An important feature of a linear equation is that the sum of two solution is also a solution. One consequence of this is that two wavepackets will chavel independently of each other. An especially clear way to demonstrate this is to set up a string with an initial profile such that there are two Gaussian wavepackets, located at different places on the string. These wavepackets (or components of them) may then propagate towards each other and collide. Show that the wavepackets are unaffected by these collisions. That is, show that two such wavepackets pass through each other without changing shape or speed.

Exercise_13 Motion of a Realistic String_第1张图片
wave

Code

import math
import matplotlib.pyplot as plt

dx = 1.0
dt = 0.1
c = 10.0
k = 0.1
t = 0
n = 0
r = c*dt/dx
y3 = list(range(101))
y2 = list(range(101))
y1 = list(range(101))
for i in range(101):
    #y3[i]=math.exp(-k*(30.0-i)**2)+2*math.sin(i)*math.exp(-k*(70.0-i)**2)
    y3[i]=math.exp(-k*(40.0-i)**2)+2*math.exp(-k*(60.0-i)**2)
    y1[i]=y3[i]
    y2[i]=y3[i]
plt.figure(figsize=(10,5))
while t<0.1:
      for i in range(101):
        y1[i]=y2[i]
        y2[i]=y3[i]
    for j in range(101):
        if j>0 and j<100:
            y3[j]=(y2[j+1]+y2[j-1])-y1[j]
    n=n+1
    t=n*dt
plt.plot(y3,label='t='+str(t-dt))
plt.ylabel('y')
plt.xlabel('x')
plt.legend(loc="upper right", frameon=True,prop={'size':20})
plt.ylim([-3,3])
plt.show()

Result

Exercise_13 Motion of a Realistic String_第2张图片
13.1
Exercise_13 Motion of a Realistic String_第3张图片
13.2
Exercise_13 Motion of a Realistic String_第4张图片
13.3
Exercise_13 Motion of a Realistic String_第5张图片
13.4
Exercise_13 Motion of a Realistic String_第6张图片
13.5
Exercise_13 Motion of a Realistic String_第7张图片
13.6
Exercise_13 Motion of a Realistic String_第8张图片
13.7

The code is given by Jingyi Zhou.

你可能感兴趣的:(Exercise_13 Motion of a Realistic String)