Link:
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_ problem&problem=1282
Original title:
Solve the Equation:p*e-x + q*sin (x) + R*cos (x) + S*tan (x) + t*x2 + u = 0 where 0 <= x <= 1.
Input
Input consists of multiple test cases and terminated by an EOF. Each test case consists of 6 integers-a single line:p, Q, R, S, T and U (where 0 <= p,r <=-and-20 <= <= 0). There is maximum 2100 lines in the input file.
Output
For each set of input, there should is a line containing the value of x, correct upto 4 decimal places, or the string "No" Solution ", whichever is applicable.
Sample Input
0 0 0 0-2 1
1 0 0 0-1 2
1-1 1-1-1 1
Sample Output
0.7071
No Solution
0.7554
Analysis and Summary:
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
The problem of solving the root of nonlinear equation, lrj the classic of algorithm p150 has similar problems. The requirement is between the 0~1, and the equation is monotonically decreasing, so you can use the two points to find the root.
* * Uva:10341-solve It
* time:0.024s
* author:d_double * * * * * * * * * * * * * */
#include &l t;iostream>
#include <cstdio>
#include <cmath>
#define EPS (10e-8)
using namespace STD;
Double p,q,r,s,t,u;
Inline double Fomula (double x) {return
p*exp (-X) +q*sin (x) +r*cos (x) +s*tan (x) +t*x*x+u;
}
int main () {
while (scanf ("%lf%lf%lf%lf%lf%lf", &p,&q,&r,&s,&t,&u)!=eof) {
double Left=0, Right=1, mid;
BOOL Flag=false;
if (Fomula (left) *fomula (right) > 0) {
printf ("No solution\n");
Continue;
}
while (Right-left > EPS) {
mid = (left+right)/2;
if (Fomula (mid) *fomula (left) > 0) left=mid;
else Right=mid;
}
printf ("%.4f\n", mid);
}
return 0;
}
Author: csdn Blog shuangde800