void getallEs(double **E, int lmax, int nmax[], double Z, double V[], double r[], double dr[], int N)Output:
- E[l][n]: matrix of energies of states of angular momentum l and n=0 nodes through n=nmax[l] nodes (inclusive!)
Input:
- lmax: maximum angular momentum to consider (l=0 through l=lmax)
- nmax[l]: maximum number of nodes sought for angular momentum l
- Z: charge on the nucleus
- V[]: ``self-consistent potential (V[k]=-Z/r[k], for now ...)
- r[], dr[], N: standard grid information
Write a routine of the above prototype which returns the energies of the electrons in an atom with potential V[]. The routine should return the results in the form of a double precision two dimensional matrix of values E[l][n]. It should determine the following table of values:
As discussed in lecture, your routine should do this by calling ``getEs'' with
A suitable, but not the most efficient, code fragment is
double *Veff;
.
.
Veff=dvector(0,N); /* Must declare space for Veff */
.
.
for (k=0; k<=N; k++) { /* Compute Veff */
Veff[k]=V[k]+l*(l+1)/(2*r[k]*r[k]);
}
Veff[0]=0.; /* Mathematically proper for origin */
.
.
getEs(E[l],nmax[l],-Z*Z,Veff,r,dr,N); /* Solve for states of ang mom l */
.
.
free_dvector(Veff,0,N); /* Must free Veff at end of routine! */
where, as discussed in lecture, we use -Z*Z as a guaranteed lower
bound. Note the convenient use of the Numerical Recipes
dvector() routine to declare space for Veff.
Hints on working with two-dimensional matrices:
Note that, if you are working in C, the above code fragment will only work if E is properly passed in as an array of pointers, which can get quite tricky unless you have a lot of experience with dealing with pointers in C. All of this is done for you by the numerical recipes ``dmatrix'' function, which you should use to form the object E in the routine which calls getallEs. Your main program for (3.2) below, for instance, would look like
{
double **E; /* In the declarations section */
.
.
E=dmatrix(0,lmax,0,nmaxmax); /* Among the first executables -
. lmax is the maximum l value we expect;
. nmaxmax is the maximum expected of all nmax[l]'s */
getallEs(E,lmax,nmax,Z,V,r,dr,N); /* Example call */
printf("E[l=0][n=0]=%f, E[l=1][n=0]=%f\n",E[0][0],E[1][0]); /* Use E[][] like this */
.
.
free_dmatrix(E,0,lmax,0,nmaxmax); /* At end of routine or main, must call free
for each dvector and dmatrix before exiting! */
}
If you are working in Fortran, then you must reverse the order of the array, so that it is used as E(n,l). The proper declaration of E, call for ``getallEs'' and write statement for the above example is then
double precision E(0:nmaxmax,0:lmax)
.
.
call getallEs(E(0,l),lmax,nmax,Z,V,r,dr,N)
write(6,*) 'E(n=0,l=0)=',E(0,0),', E(n=0,l=1)=',E(0,1)
Note that, here, the first argument to E is the number ``one'' and the
second argument is the letter ``ell''. Finally, in Fortran,
getallEs needs to know the dimensions of E, so you'll have to add one
more argument to the prototype as in
subroutine getallEs(E,lmax,nmax,Z,V,r,dr,N,nmaxmax)
double precision E(0:nmaxmax,0:lmax)
integer lmax
integer nmax(0:lmax)
double precision Z
double precision V(0:N)
double precision r(0:N),dr(0:N)
int N