环境51,Keil UV4
写一段程序用于对两组数据求一元线性回归,在执行到这句时遇到问题:
float VTk;
unsigned long SigmaVjTj,SigmaVj,SigmaTj;
VTk=(float)(SigmaVjTj-SigmaVj*SigmaTj/j)/(SigmaVj2-SigmaVj*SigmaVj/j);
其中SigmaVjTj=2660200
SigmaVj=2564
SigmaTj=5500
j=5
按说计算后应当为VTk= - 5.609872255,实际调试中我用如下语句
PrintChar(24,60,(unsigned char)VTk/1000000+48,1);
PrintChar(30,60,(unsigned char)VTk%1000000/100000+48,1);
PrintChar(36,60,(unsigned char)VTk%100000/10000+48,1);
PrintChar(42,60,(unsigned char)VTk%10000/1000+48,1);
PrintChar(48,60,(unsigned char)VTk%1000/100+48,1);
PrintChar(54,60,(unsigned char)VTk%100/10+48,1);
PrintChar(60,60,(unsigned char)VTk%10+48,1);
把结果打印到LCD,值为000,0122
实在是搞不出来了,向各位高手求救,Help~
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
SigmaVj*SigmaTj/j 会把浮点数小数部分丢掉
一周热门 更多>