本文共 802 字,大约阅读时间需要 2 分钟。
题意:解方程
p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1.(0 <= p,r <= 20 and -20 <= q,s,t <= 0)
题目链接:
观察可得 求导可得此函数是递减函数 判断是否有解即 f(0) * f(1) <= 0
在此还要懂得运用 三角函数 ,还有求e^(-x) ,要用到exp函数求解 e^(-x) = exp(-x);
三角函数sin(x) 中x指的经过角度变化的弧度
解决此题用二分求解
#include#include double p,q,r,s,t,u;double f(double x){ return p*exp(-x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u ;}void find(double x,double y){ double mid; while(y - x > 0.000000001) { mid =( x + y ) / 2 ; double t = f(mid) ; if(t < 0) y = mid; else x = mid ; } printf("%.4lf\n",mid);}int main(){ while(scanf("%lf%lf%lf%lf%lf%lf",&p,&q,&r,&s,&t,&u)!=EOF) { if(f(0) * f(1) > 0) printf("No solution\n"); else { find(0.0,1.0); } }}
转载地址:http://uysgi.baihongyu.com/