开发平台(Platform): Win10
编译器(DEC C++)
问题(Question):小弟我利用C语言算一些算式结果算出来有些是对的
不过有些会大的很夸张,也会出现-1.QNANO爬文查google之后还是没办
法解决想上来问各位是哪里要改资料型态吗?
CODE:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
int i,j,k;
srand(time(NULL));
int u1[50];
float ep[50];
float yk[50];
float ystar[50];
float u[50];
float V[2][5] =
{{-0.9,1.8,0.4,0.5,0.7},{-0.2,0.7,-0.3,-1.4,0.5}};
float W[5][4] =
{{-2.2,1.9,2.7,5.2},{-4.3,-2.9,0.5,1.8},
{-2.0,1.1,-0.6,1.5},{-1.2,1.3,-0.4,1.6},{3.1,1.3,1.2,2.2}};
for(i=0;i<50;i++)
{
u1[i]=(rand()%90)+1;
u[i]=(float)u1[i]/100; //产生50个u[0,1]
//printf(" %d. %1f\n",i,u[i]);
yk[0]=0.0;
ystar[0] =0.0;
yk[i+1] = yk[i]*0.9048 + u[i]*0.09516; //得到50个yk
for(j=0;j<4;j++)
{
for(k=0;k<5;k++)
{
ystar[i] = ystar[i] + ((V[0][k])*yk[i]+(V[1][k])*u[i])*(W[k][j]);
}
}
printf("%d. %f\n",i,ystar[i]);
}
system("pause");
}
预期的正确结果(Expected Output):都是正常的值
错误结果(Wrong Output):会出现类似95478000000000或-1.QNANO值
谢谢大家帮我解惑