c语言不知道为什么结果是-9.25596313493178E+610
会走路的笔2015.05.07浏览90次分享举报
#include
#include
void main()
{
double U[301],U1[301],U2[301],U3[301],NN1,NN2,NN3,T[301]={0},ot,ox;
int k,n,N,N1,N2,N3,a=1;
ox=0.01;//空间步长
ot=ox*ox/2;//ot=2*ox,时间步长
NN1=0.2/ot;
NN2=2.0/ot;
NN3=10/ot;
N1=int(NN1);
N2=int(NN2);
N3=int(NN3);
N=N3;
FILE *FP1,*FP2,*FP3;
FP1=fopen("c:\\1.xls","w+");
FP2=fopen("c:\\2.xls","w+");
FP3=fopen("c:\\3.xls","w+");
for(k=0;k<100;k++)
U[k]=0;
for(k=100;k<200;k++)
U[k]=1;
for(k=201;k<300;k++)
U[k]=0;
U[0]=U[300];
for(n=1;n
{
for(k=1;k<300;k++)
T[k]=(U[k+1]+U[k-1])/2-(a*ot/(2*ox))*(U[k+1]-U[k-1]);
for(k=1;k<300;k++)
U[k]=T[k];
if(n=N1)
for(k=0;k<=300;k++)
U1[k]=U[k];
if(n=N2)
for(k=0;k<=300;k++)
U2[k]=U[k];
if(n=N3)
for(k=0;k<=300;k++)
U3[k]=U[k];
}
{
for(k=0;k<=300;k++)
fprintf(FP1,"%lf\n",U1[k]);
for(k=0;k<=300;k++)
fprintf(FP2,"%lf\n",U2[k]);
for(k=0;k<=300;k++)
fprintf(FP3,"%lf\n",U3[k]);
}
}
具体其中一个结果,由于字数限制,中间许多0和1被我删除。。。主要是有 -9.25596E+61,不知道哪里出错了。。。
-9.25596E+61
-4.65112E+61
0
0
0
0
0
0
0
0
0.4975
0.4975
1
1
-4.60484E+61
0.5025
-4.65112E+61
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-4.60484E+61
-9.25596E+61