/* code integrates 1d Schroedinger eqn. using a shooting method. */ /* adapted to cope with NUM identical potential wells */ /* general well width W, depth V, well wall thickness A*/ /* setting NUM to 1 and A to zero gives single well of width 2*W*/ /* setting NMUM to 1 and A non-zero gives chemical bond potential */ /* setting NUM large yields 1d crystal - see band structure */ /* potential is set to zero outside the well - until it encounters a hardwall *//* at LARGE_X */ #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 POT_LEN (NUM*(W+A)) #define LARGE_X (POT_LEN+W) /* 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;iLARGE_X) return(10.0/RESOL); if(x>POT_LEN) return(0); /* first find which well you are in */ idum=(int)(x/(A+W)); /* next find position within this well */ xdum=x-idum*(A+W); if(xdum(W+A/2)) return(0); return(V); }