int schint(double *Psi, double *Psip, double Psiout[],
int k1, int k2, double V[], double E,
double r[], double dr[], int N)
Return value:
Output:
Input:
As we learned in Lab2, solving for the energies can be accomplished by
setting the boundary conditions at one end point of the problem (e.g.,
), and investigating the resulting behavior at the other end
point (e.g.,
). As we will see later in this problem
set, it is also very useful to count the number of times that the
solution crosses zero (number of ``nodes''). Accordingly, write a
function of the above form in ``physics.c'' and include its prototype
in ``physics.h''.
Note that to write this routine, you should be able to take the appropriate parts from your ``quicksch.c'' program and repackage them as a subroutine. There are a number of details to consider. Among these are
The last of these considerations is a bit tricky because T[] is not passed in as a variable, and the routine thus must allocate the space for the array it without ``knowing'' how much space is needed until the actual call is made. One solution would be to declare a fixed, large amount of space, but this is wasteful and can cause bugs if the size is exceeded. The best way to handle this kind of situation is ``dynamic memory allocation,'' where the space for T[] is allocated while the programming is running. Fortunately, nrutil.c includes functions for doing just this. To accomplish this, you should declare the variable T (technically, a pointer) in the declarations section of schint() using
double *T;and, then, allocate the space for T[] as one of the first statements in the program using
T=dvector(0,N);This latter statement sets up space for an array T[] which holds values T[0], T[1], ..., T[N]. The last, but most important, detail in dynamic memory allocation is to be sure to free up the space. Otherwise, each time the routine is called, it will eat up more program space, and eventually your code will slow down and crash (and possibly even crash the machine...)!
To avoid this, you should clean up the space when you are done with it, by including the following statement at the very end of schint(),
free_dvector(T,0,N);
Tomas Arias 2005-02-17