我目前正在学习计算物理课程。我是计算物理学和一般编程的新手。我正在使用数值方法来尝试将径向薛定谔方程与 Lennard-Jones 势相结合。
Numerical recipes 有一个名为 odeint 的函数,它将使用五阶 Runge-Kutta 算法为您积分一个常微分方程。该函数具有可调整的步长,这似乎导致我的代码出现问题。也就是说,我的步长将变为零,这会导致数值配方抛出错误并过早退出。
我在数值上从到进行积分,并在分析上达到我的最小值,以处理零处的奇点。我在下面附上了我的代码,有关 odeint 及其工作原理的更多信息,请访问:http ://www.itp.uni-hannover.de/Lehre/cip/odeint_c.pdf 。谁能帮我理解我哪里出错了?
#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
这输出
Numerical Recipes run-time error...
stepsize underflow in rkqs
...now exiting to system...