环境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~
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
{
//float temp_f = 0.0;int temp_i = 0;
flag <<= 1; //乘以2
if(value<a[flag+1])
{
temp_f = ((float)(a[flag+1]-value))/b[flag+1];
//temp_i = temp_f*100;
URAT_Send_data('-');
}//if
else
{
temp_f = ((float)(value-a[flag+1]))/b[flag+1];
//temp_i = temp_f*100;
URAT_Send_data('+');
}//else
//(*(gravity+flag))=(0.9)*(*(gravity+flag))+(0.1)*temp_f;
//(*(linear+flag))=temp_f-(*(gravity+flag));
//temp_i = (*(gravity+flag))*100;
//temp_i = (*(linear+flag))*100;
temp_i = (unsigned long)(temp_f*100.0);
URAT_Send_data(temp_i/100+'0');
URAT_Send_data('.');
URAT_Send_data(temp_i%100/10+'0');
URAT_Send_data(temp_i%10+'0');
URAT_Send_data('g');
URAT_Send_data(' ');
}//SmallRange
我必须先判断value和a[flag+1]的大小才能正确的向串口调试助手发送数据,我想请教的是怎么才能不需要判断value和a[flag+1]的大小就可以向串口调试助手发数据啊?
一周热门 更多>