UVa 10341:solve It

Source: Internet
Author: User
Tags cos printf sin

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.