Zeroes of polynomials P97780


Statement
 

pdf   zip

Given a function ff continuous in an interval [a,b][a,b], and such that f(a)f(b)<0f(a) \cdot f(b) < 0, a basic theorem of Mathematics states that there must exist at least one zero of ff in (a,b)(a,b), that is, a real number zz such that a<z<ba < z < b and f(z)=0f(z) = 0.

Given a polynomial p(x)=c4x4+c3x3+c2x2+c1x+c0p(x) = c_4 x^4 + c_3 x^3 + c_2 x^2 + c_1 x + c_0 with exactly one zero in (0,1)(0,1), can you find this zero?

Input

Each input line describes a polynomial p(x)p(x) of degree at most 4 with exactly one zero in (0,1)(0,1). Each polynomial is given in decreasing order of ii as follows: c44c33c22c11c00c_4\ 4\ c_3\ 3\ c_2\ 2\ c_1\ 1\ c_0\ 0. Every cic_i is a real number. The pairs ciic_i\ i with ci=0c_i = 0 are not present in the input.

Output

For every polynomial, print its case number, followed by an approximation of its zero zz in (0,1)(0,1), with the following convention: zz must be a real number with exactly 5 digits after the decimal point, such that 0z0.999990 \le z \leq 0.99999 and p(z)p(z+0.00001)<0p(z) \cdot p(z + 0.00001) < 0. Always print the 5 decimal digits of zz.

Observations

  • Every given polynomial is such that p(x)0p(x) \ne 0 for every real number x[0,1]x \in [0,1] that has 5 (or less) decimal digits after the decimal point.

  • The test cases have no precisions issues. However, be aware that it is not wise to check the property p(z)p(z+0.00001)<0p(z) \cdot p(z + 0.00001) < 0 just like this.

Public test cases
  • Input

    -1 2 0.5 0
    4 3 -6 1 1 0
    4.65 4 -0.11 3 0.53 2 -6.51 1 0.13 0
    6.31 4 7.64 3 -5.29 2 0.55 1 -9.2 0
    

    Output

    Case 1: zero at 0.70710.
    Case 2: zero at 0.16993.
    Case 3: zero at 0.02000.
    Case 4: zero at 0.99973.
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C C++