Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Newton’s Method
Description While solving non-linear equations in numerical analysis lesson, professor Busoniya introduce us Newton's Method. Like the other ways (such as bisection, Muller's Method), this method is also based on a linear approximation of the function, but does so using a tangent to the curve. The figure below gives a graphical description. Starting from a single initial estimate, x. The general term is: _{1}x = _{n+1}x - f(_{n}x) / f′(_{n}x), n = 0, 1, 2, .... Newton’s algorithm is widely used because it is more rapidly convergent than any of the methods discussed so far. Then now, you task is to accurate how many iterations it takes to get a root using Newton's Method. The _{n}x and the equation are given and all the tolerance is 0.000001. You just use this method to get the answer. The iteration will stop when |_{0}x - _{n+1}x| < tolerance or |f(_{n}x)| < tolerance then n is the answer. But sometimes the _{n}x or equation we choose is so bad that we cannot get the answer using this method within 1000 iterations, then just output "Bad x0 or bad equation!" _{0}Input There are multiple cases ended by EOF. Each case has two lines, first line is the equation and the second line is Output For each test case, output n or "Bad x0 or bad equation!" per line. Sample Input -3x^2 -3 = 0 3 3x -3 = 0 1 5x^2 -2 = 0 -5 Sample Output Bad x0 or bad equation! 0 6 Source POJ Monthly Contest – 2009.04.05, longpo |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator