某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);
}
【某IT外企面试题-二分法求方程】相关文章:
外企应聘最常问的英文面试题09-05
关于外企求职常见的英语面试题10-02
面试外企技巧01-29
外企offer模板11-14
外企面试礼仪12-16
求份租房合同02-09
求青春励志歌曲10-15
求面试的技巧01-01
某外资公司offer模板11-15