Solving cos(x)-sqrt(x) using Newton Raphson method for x ∈ [0,4]

229 Views Asked by At

I am trying to solve to the equation

f(x) = cos(x) - sqrt(x)

using Newton-Raphson Method in python

f'(x) = -sin(x) - (1/2*sqrt(x))

For my starting guess, I'm trying values form 0 to 4. It works fine from the range 0.00001 to 2.45

The graph looks like this enter image description here

But my code fails (gives nan) when I enter values beyond 2.45. It also fails at 0. I'm not able to understand the mathematical logic behind this. Any help would be really helpful.