/* code integrates 1d Schroedinger eqn. using a shooting method. */ /* general well width W, depth V, well wall thickness A, number of wells NUM*/ /* potential is set large for x=LARGE_X (helps with robustness of code) */ /* LARGE_X should be taken to be total length of potential plus 5.0 */ /* finds ALL energy levels between MAX_ENERGY and MIN_ENERGY */ /* set for 1 well at the moment */ #include #include /* function prototypes */ double find_energy(double ue, double le); double wavefunction_at_large_x(double e); void integrate(int i, double e); double potential(double x); /* parameters of the potential */ #define V -1.0 #define W 10.0 #define A 0.0 #define NUM 1 #define LARGE_X 15.0 /* largest number of steps allowed */ #define MAX 100000 /* xstep and wavefunction accuracy */ #define DX 0.01 #define RESOL 0.001 /* find all solutions up to MAX_ENERGY assuming the average gap between */ /* sucessive allowed energies is ENERGY_GAP; */ #define MAX_ENERGY 0.0 #define MIN_ENERGY V #define ENERGY_GAP 0.0005 /* PARITY may be 0 or 1 depending on whether the wavefunction is odd or even */ #define PARITY 0 /* wavefunction */ double psi[MAX],dpsi[MAX]; /* number of steps */ int N; int main(void){ FILE *fp; char s[25]; int i; double energy,norm; int outerloopcount=0; /* search intervals for energy and resolution */ double upper_energy=MIN_ENERGY,lower_energy=MIN_ENERGY; /* sign of wavefunction at large x using upper and lower energies */ double upper_energy_sign,lower_energy_sign; N=(int)LARGE_X/DX; if(N>MAX){(void)printf("Increase size of arrays - MAX variable\n");exit(1);} lower_energy_sign=wavefunction_at_large_x(lower_energy); /* loop incrementing the upper_energy until an interval is found which */ /* contains a possible allowed energy */ while(upper_energy0.0){ sl=s; le=e; } else{ su=s; ue=e; } }while(fabs(s)>RESOL); (void)printf("Number of iterations to locate energy %d\n",count); (void)fflush(stdout); return(e); } double wavefunction_at_large_x(double e){ /* integrates out to large x and returns value of psi there */ int i; psi[0]=(1-PARITY); dpsi[0]=PARITY; for(i=0;i