I'm currently taking a course in computational physics. I'm new to computational physics and programming in general. I'm using numerical recipes to try and integrate the radial Schrodinger equation with a Lennard-jones potential.
$$\left[ \frac{\hbar^2}{2m}\frac{d^2}{dr^2} + \left( E-V(r)-\frac{\hbar^2 l (l+1)}{2mr^2}\right) \right] u_l(r)=0$$
$$V(r)= \epsilon \left[ \left( \frac{\rho}{r} \right)^{12}-2\left(\frac{\rho}{r}\right)^6 \right]$$
Numerical recipes has a function called odeint which will use a fifth-order Runge-Kutta algorithm to integrate an ordinary differential equation for you. The function has an adjustable step-size which appears to be causing problems in my code. Namely, my step-size is going to zero, which causes numerical recipes to throw an error and exit prematurely.
I am doing the integration from $r_{min}=\frac{\rho}{2}$ to $r_{max}=5\rho$ numerically, and up to my minimum value analytically in order to take care of the singularity at zero. I have attached my code below, and more information on odeint and how it works can be found at: http://www.itp.uni-hannover.de/Lehre/cip/odeint_c.pdf. Can anyone help me understand where I'm going wrong?
#include <stdio.h>
#include <math.h>
#define NRANSI
#include "nr.h"
#include "nrutil.h"
#define N 2
float dxsav,*xp,**yp; /* defining declarations */
int kmax,kount;
int nrhs; /* counts function evaluations */
/* Schrodinger equation and L-J parameters */
double alpha = 6.12;
double rho = 3.57;
double epsilon = 5.9;
double l = 1.0;
double energy = 3;
double rmin=1.785;
double rmax=17.85;
void derivs(float x,float y[],float dydx[])
{
nrhs++;
printf("xodeint check: x=%f\n", x);
dydx[1] = y[2];
dydx[2]=alpha*((l*(l+1)/(alpha*x*x))+epsilon*(pow(rho/x,12)-2*pow(rho/x,6))-energy)*y[1];
}
int main(void)
{
int i,nbad,nok;
float eps=1.0e-4,h1=0.1,hmin=0,x1=rmin,x2=rmax,*ystart;
ystart=vector(1,N);
xp=vector(1,200);
yp=matrix(1,10,1,200);
ystart[1]=0.93583;
ystart[2]=0.17385;
nrhs=0;
kmax=100;
dxsav=(x2-x1)/20.0;
// printf("%f\n", h1);
odeint(ystart,N,x1,x2,eps,h1,hmin,&nok,&nbad,derivs,rkqs);
printf("\n%s %13s %3d\n","successful steps:"," ",nok);
printf("%s %20s %3d\n","bad steps:"," ",nbad);
printf("%s %9s %3d\n","function evaluations:"," ",nrhs);
printf("\n%s %3d\n","stored intermediate values: ",kount);
printf("\n%8s %18s %15s\n","r","integral","x^2");
for (i=1;i<=kount;i++)
printf("%10.4f %16.6f %14.6f\n",xp[i],yp[1][i],xp[i]*xp[i]);
free_matrix(yp,1,10,1,200);
free_vector(xp,1,200);
free_vector(ystart,1,N);
return 0;
}
#undef NRANSI
This outputs
Numerical Recipes run-time error...
stepsize underflow in rkqs
...now exiting to system...
hmin
? It seems that your error comes from hereif (errmax > 1.0) { h=SAFETY*h*pow(errmax,PSHRNK); if (h < 0.1*h) h *= 0.1; xnew=(*x)+h; if (xnew == *x) nrerror("stepsize underflow in rkqs"); continue; }
$\endgroup$