Solve the equation:
p∗e−x + q∗sin(x) + r∗cos(x) + s∗tan(x) + t∗x2 + u = 0where 0 ≤ x ≤ 1.InputInput consists of multiple test cases and terminated by an EOF. Each test case consists of 6 integers in a single line: p, q, r, s, t and u (where 0 ≤ p, r ≤ 20 and −20 ≤ q,s,t ≤ 0). There will be maximum 2100 lines in the input file.OutputFor each set of input, there should be a line containing the value of x, correct up to 4 decimal places, or the string ‘No solution’, whichever is applicable.Sample Input0 0 0 0 -2 1 1 0 0 0 -1 2 1 -1 1 -1 -1 1Sample Output0.7071 No solution 0.7554观察题目中的条件,方程必定在定义域内单调递减,逻辑方面就很容易了。
在实现上,使用二分找到一个满足条件的解,不过我一开始使用的whlie循环居然会超时,后来换成for循环就过了,后来才发现我的循环有问题
while(abs(f(mid))>=MIN) { if(f(mid)>=MIN) fir=mid,mid=(fir+las)/2; else las=mid,mid=(fir+las)/2; }
判断结束的精确度不应该是用函数值,而应该是用mid,下面for循环通过代码
#include#include #include #include #include #include #include