算法应该没问题啊,我把程序改成matlab语言,求解得出正确结果,那为什么用C++不能得出正确结果呢
#include "math.h"#include "iostream.h"
void main()
{
double a;
double du=3.1415926/180;
double m_height=1;
double m_length=40;
double m_result=-90*du;
double m_orientangel=45*du;
double m_sideangel=4*du;
double m_frontangel=4*du;
a=m_height+m_length*cos(m_result)*cos(m_orientangel)*tan(m_sideangel)+m_length*cos(m_result)*sin(m_orientangel)*tan(m_frontangel)-m_length*sin(m_result);
while(abs(a)>10e-6)
{
m_result=m_result+10e-3;
a=m_height+m_length*cos(m_result)*cos(m_orientangel)*tan(m_sideangel)+m_length*cos(m_result)*sin(m_orientangel)*tan(m_frontangel)-m_length*sin(m_result);
}
cout<<m_result/du<<endl<<a<<endl;
}
我试了一下,发现最后a就是误差稳定在了1附近,真是搞不懂