#include<iostream.h>
#include<math.h>
double V=-5,W=1,Emin=-20,Emax=20,M=30,E,G1,G2,A,B,C,D,De,N,dwf1,dwf2,wf1,wf2,Test,nodes,Nlast;
char pan;
void wfcoef()
{
G1=sqrt(fabs(V-E));
G2=sqrt(fabs(E));
wf1=1;
dwf1=G2;
A=G2/G1;
B=1;
wf2=A*sin(G1*W)+B*cos(G1*W);
dwf2=G1*A*cos(G1*W)-B*G1*sin(G1*W);
C=0.5*exp(-G2*W)*(wf2+dwf2/G2);
D=0.5*exp(G2*W)*(wf2-dwf2/G2);
return;
}
int main()
{
cout<<'\t'<<'\t'<<"***********************************************"<<endl;
cout<<'\t'<<'\t'<<" 一维势阱基态能量本征值计算软件"<<endl<<endl;
cout<<'\t'<<'\t'<<" 预设精度0.0001 dss "<<endl;
cout<<'\t'<<'\t'<<"***********************************************"<<endl;
aa: cout<<endl<<"请依次输入 V,W,Emin,Emax,M 值 :"<<endl;
cout<<"数据用空格或回车隔开,以回车结束,要求势阱深度V<0,宽度W>0,能量分割M>1且为整数"<<endl;
cout<<"例如:-5 1 -20 20 30"<<endl<<endl;
cin>>V>>W>>Emin>>Emax>>M;
bb: if(M>1)
{
N=0;
De=(Emax-Emin)/double(M-1);
E=Emin-De;
for(int i=0;i<M;i++)
{
E+=De;
wfcoef();
nodes=G1*W/3.1415926;
Test=-C/D;
if(Test>0)
nodes++;
if(!i)
Nlast=nodes;
else
Nlast=N;
N=nodes;
cout<<E<<'\t'<<N<<endl;
if(int(N)==1 && int(Nlast)==0)
{
if(De>=0.0001)
{
cout<<endl<<"缩小能量搜索范围及步长,提高精度再次迭代计算!"<<endl<<endl;
Emin=E-De;
Emax=E;
goto bb;
}
else
{
cout<<endl<<endl<<"基态能量本征值为:"<<E-De/2<<'\t'<<"误差:"<<De<<endl<<endl;
cout<<"计算结束,是否继续计算 y/n :";
cin>>pan;
if(pan=='y')
goto aa;
else
return 0;
}
}
}
}
else
{
cout<<endl<<"输入错误: M<=1"<<endl<<endl;
goto aa;
}
cout<<endl;
cout<<"##########################################################################"<<endl;
cout<<" 对不起,未能找到基态能量本征值!"<<endl;
cout<<" 请尝试扩大能量范围或增大M"<<endl;
cout<<"##########################################################################"<<endl<<endl;
goto aa;
}