[关闭]
@c-xy 2016-12-19T15:28:12.000000Z 字数 1640 阅读 172

第十三次作业


一、背景
The central equation of wave motion is


We treat x and t as discrete variables with i and n,That isand.We can obtain:

whereand then restricting the updating of y(i,n)
Tiypically,we might know the string configuration at t=0,which we refer to as .
The another problem is to how to treat the ends of the string.We consider fixed ends,and then restricting the updating of y(i,n)to the interior of the string(from i=1 to i=m-1).
We should choose r=1,if we were to cutin half but keep fixed so that r=2,the algorithm becomes unstable. This signal can be decomposed into Fourier components.That is ,we can write the signal as a sum of sines and cosines with different frequencies and amplitudes.
二、代码

  1. import numpy as np
  2. import matplotlib.pyplot
  3. from pylab import *
  4. from math import *
  5. import mpl_toolkits.mplot3d
  6. k=1000
  7. dx=0.01
  8. c=300.0
  9. dt=dx/c
  10. y=[[0 for i in range(100)]for n in range(3000)]
  11. x=np.linspace(0,1,100)
  12. t=np.linspace(0,0.1,3000)
  13. r=c*dt/dx
  14. for i in range(31):
  15. y[0][i]=0.8*x[i]
  16. y[1][i]=0.8*x[i]
  17. for i in range(30,100):
  18. y[0][i]=-2.4/70*x[i]+24/7
  19. y[1][i]=-2.4/70*x[i]+24/7
  20. for n in range(3000):
  21. for i in range(1,99):
  22. y[n][i]=2*(1-r**2)*y[n-1][i]-y[n-2][i]+r**2*(y[n-1][i+1]+y[n-1][i-1])
  23. y4=[]
  24. for n in range(len(t)):
  25. y4.append(y[n][30])
  26. figure(figsize=[16,8])
  27. subplot(121)
  28. plot(t,y4)
  29. title('string signal versus time')
  30. xlabel('time(s)')
  31. ylabel('signal')
  32. xlim(0,0.11)
  33. subplot(122)
  34. p=abs(np.fft.rfft(y4))**2
  35. f = np.linspace(0, int(1/dt/2), len(p))
  36. plot(f, p)
  37. xlim(0,3000)
  38. xlabel('Frequency(Hz)')
  39. ylabel('Power')
  40. title('Power spectrum')
  41. show()

三、致谢
感谢室友进行的指导。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注