Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. N = 256
  2. x = np.linspace(-10,10,N)
  3. c=16
  4. delta_x = x[2]- x[1]
  5. delta_k = 2*np.pi/(N*delta_x);
  6. k = np.arange(0,0.001, delta_k)
  7. u = 1/2*c*(1/np.cosh(np.sqrt(c)/2*(x+8)))**2
  8. delta_t = 0.4/N**2
  9. tmax = 0.1
  10. nmax = round(tmax/delta_t)
  11. U = np.empty((len(x),nmax))
  12. U[:,0] = np.fft.fft(u)
  13. for i in range (1, nmax):
  14. #frst we solve the linear part
  15. U[:,i] = U[:,i-1]*np.exp(1j*k**3*delta_t);
  16. # then we solve the non linear part
  17. U[:,i] = U[:,i] - delta_t*(3j*k*np.fft.fft(np.real(np.fft.ifft(U[:,i]))**2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement