某IT外企面试题-二分法求方程
//f(x)=RMAX-R+(R-r)*double (cos(0.5*x))+double (sqrt(r*r-(R-r)*(R-r)* sin(0.500*x)* sin(0.500*x)))
请用二分法或其他方法求出解x.要求精度esp=1e-5
其中RMAX,R,r从键盘输入。
#include
#include
void get(double RMAX,double R,double r,double x,double y)
{
double m,n,c,p;
double esp=1e-5;
do
{
m=RMAX-R+(R-r)*double (cos(0.5*x))+double (sqrt(r*r-(R-r)*(R-r)* sin(0.500*x)* sin(0.500*x)));
n=RMAX-R+(R-r)*double (cos(0.500*y))+double (sqrt(r*r-(R-r)*(R-r)* sin(0.500*y)*sin(0.500*y)));
c=0.500*(x+y);
p=RMAX-R+(R-r)*double (cos(0.500*c))+double (sqrt(r*r-(R-r)*(R-r)* sin(0.500*c)*sin(0.500*c)));
if(fabs(p)
break;
else if(m*p<0)
{
x=x;
y=c;
}
else if (m*p>0)
{
y=y;
x=c;
}
}while(fabs(y-x)
cout<<\”The value of angle:tt\”<<(x+y)*0.5<
cout<<<\” \”<<<\” \”<<
}
void main()
{
double RMAX,R,r,x,y;
cout<<\”input RMAX,R,r,x,y:\”<
cin>>RMAX;
cin>>R;
cin>>r;
cin>>x;
cin>>y;
get(RMAX,R,r,x,y);
}
版权声明:此文自动收集于网络,若有来源错误或者侵犯您的合法权益,您可通过邮箱与我们取得联系,我们将及时进行处理。
本文地址:https://www.gunzhua.com/jiuye/bishi/44509.html