Zeroes of polynomials P97780


Statement
 

pdf   zip

thehtml

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

Given a polynomial p(x) = c4 x4 + c3 x3 + c2 x2 + c1 x + c0 with exactly one zero in (0,1), can you find this zero?

Input

Each input line describes a polynomial p(x) of degree at most 4 with exactly one zero in ‍(0,1). Each polynomial is given in decreasing order of ‍i as follows: c4 4 c3 3 c2 2 c1 1 c0 0. Every ci is a real number. The pairs ci i with ci = 0 are not present in the input.

Output

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

Observations

  • Every given polynomial is such that p(x) ≠ 0 for every real number x ∈ [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) < 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++