Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. // file:shooting_method_normalization.cpp
  2. //
  3. // This program solves the schroedinger equation for an infinite square well using the shooting method
  4. //
  5. // Programmer: XXXXX
  6. //
  7. //
  8. // Notes:
  9. // * compile with: the corresponding make file, make_shooting_method_normalization
  10. //
  11.  
  12. //*********************************************************************//
  13.  
  14. // include files
  15. #include <iostream> // this has the cout, cin definitions
  16. #include <cmath> // useful math functions
  17. #include <fstream> // allows me to stream things into data files
  18. #include <iomanip> // use things such as setprecision and setw
  19. using namespace std; // if omitted, then need std::cout, std::cin
  20.  
  21. //*********************************************************************//
  22.  
  23.  
  24. int
  25. main ()
  26. {
  27. //first define the variables needed for finding the wave function and normalizing it.
  28. double L = 1.0; //length of well
  29. double hc = 2.0;
  30. double psi = 0.0; //guess wavefunction
  31. double dpsi = 1.0; //first derivative of the wavefunction
  32. double ddpsi = 0.0; //second derviative of the wavefunction
  33. double E = 2.40; //Energy found through shooting method
  34. double x = 0;
  35. double dx = .01;
  36. double V = 0; //potential energy
  37. double xt = 0;
  38. double b = 4.37; //test normalization factor for numerical method. Change around to find correct factor.
  39. double wavefunct = 0; //known wavefunction
  40. double normalize = 0;
  41. double A = 0;
  42. double pi=atan(1.0)*4.0;
  43. double psinormal=0;
  44.  
  45. //will first integrate the analytical solution to find a normalized probability density
  46. ofstream out2;
  47. out2.open ("analytical_solution.dat");
  48. out2 << "x*t wavefunction^2"<<endl;
  49. for (double j=0.0; j<=L; j +=.01)
  50. {
  51. xt=0;
  52. wavefunct=sqrt(2/L)*sin(pi*j/L);
  53. normalize=normalize+(wavefunct*wavefunct*dx);
  54. xt=xt+j;
  55.  
  56. out2<<fixed<<setprecision(8)<<setw(5)<<xt<< " "
  57. <<fixed<<setprecision(8)<<setw(5)<<wavefunct*wavefunct<< " "
  58. <<endl;
  59. }
  60. out2.close();
  61.  
  62. cout<<" The integrated probability density of the analytical function is:"<<normalize<<endl;
  63.  
  64.  
  65.  
  66.  
  67. //now will integrate my numerical algorithm to find to normalize it.
  68. ofstream out;
  69. out.open ("numerical_solution.dat");
  70. out<< " x psinormal^2 "<<endl;
  71. for (double i=0.0; i<=L; i +=.01)
  72. {
  73. x=0; //for reinitialization
  74. ddpsi=-2*hc*(E-V)*psi; //second derivative of the wave function
  75. dpsi=dpsi+ddpsi*dx; //first derivative of the wave function
  76. psi=psi+dpsi*dx; //wave function
  77. x=x+i; //calculates the x value fo the particle from 0 to L
  78.  
  79. psinormal=b*psi;
  80.  
  81. A=A+psinormal*psinormal*dx;
  82.  
  83.  
  84. out<<fixed<<setprecision(8)<<setw(5)<<x<< " "
  85. <<fixed<<setprecision(8)<<setw(5)<<psinormal*psinormal<< " "
  86. <<endl;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement