Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. function test( N, ubound )
  2.  
  3. rs = linspace( 0.0, ubound, N )
  4. dr = ubound / (N - 1)
  5.  
  6. rfunc = rs .* exp( - rs )
  7.  
  8. integral = - imag( fft( rfunc ) ) * dr
  9.  
  10. file = open( "test.dat", "w" )
  11.  
  12. for m = 1 : N
  13.  
  14. if m == 1
  15. q = 0.0
  16. H = 0.0
  17. elseif m < div( N, 2 )
  18. q = (2 * pi / ubound) * (m - 1)
  19. H = integral[ m ]
  20. else
  21. q = - (2 * pi / ubound) * ( N - m + 1 ) # correct?
  22. H = integral[ m ]
  23. end
  24.  
  25. H_exact = 2 * q / ( q^2 + 1 )^2
  26.  
  27. if 0 <= q <= 200.0
  28. @printf( file, "%20.10e %20.10e %20.10en",
  29. q, H, H_exact )
  30. end
  31. end
  32.  
  33. close( file )
  34. end
  35.  
  36. test( 10^6, 50.0 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement