# Newton-Raphson Method With Complex Numbers

• I
person123
TL;DR Summary
How do you find real roots using Newton-Raphson method on functions that are only real for part of their domain?
I'm trying to code Newton Raphson's method for finding zeros. I realize that even if the solution is real, it's possible for guesses to be complex. For example:

$$y=\sqrt{x-6}-2$$

While 10 is a valid real root, for any guess less than 6, the result is complex.

I tried to run the code allowing for complex numbers, starting with 1. It converged on ##11+8.94i## which may be a solution, but I was hoping it would be able to find the real solution of 10.

Would it be possible to get the method to find real roots on functions with complex values, without a priori knowing where the real part of the domain is?

Thanks!

Mentor
TL;DR Summary: How do you find real roots using Newton-Raphson method on functions that are only real for part of their domain?

I'm trying to code Newton Raphson's method for finding zeros. I realize that even if the solution is real, it's possible for guesses to be complex. For example:

$$y=\sqrt{x-6}-2$$

While 10 is a valid real root, for any guess less than 6, the result is complex.

I tried to run the code allowing for complex numbers, starting with 1. It converged on ##11+8.94i## which may be a solution, but I was hoping it would be able to find the real solution of 10.

Would it be possible to get the method to find real roots on functions with complex values, without a priori knowing where the real part of the domain is?

Thanks!
I don't see how ##x = 11 + 8.94i## could be anywhere near a solution of the given equation. If I subtract 6 from the number above, I get ##5 + 8.94i##, which is a complex number whose magnitude is about 10.24, and that makes an angle of about 60.74° with the positive real axis. The square root of this number must therefore have a magnitude of about 3.2 (~##\sqrt{10.24}##) and make an angle of about 30.37° with the positive real axis. Finally, subtracting 2 from this potential solution doesn't get us anywhere close to 0, so that x value can't be a solution.

Homework Helper
Gold Member
For a complex function, for some initial guesses the method will not converge, see here.
If you know the real part of the domain, you'd likely have success by trying one initial guess in each connected component of that domain. But absent that knowledge, you can't do anything much. You could write a program to try to identify real parts of the domain, and then use those. But it might miss some, eg if they were very narrow. For instance the function:
$$f(x) = 0.01 -\sqrt{0.01^2 - (x-10)^2}$$
is only real on ##[9.99, 10.01]## and has a single root 10. An algorithm searching for a region where the function is real could easily miss that small interval.

person123 and topsquark
person123
Thank you!

I guess I'll stick with initially searching for real parts of the domain as @andrewkirk suggested, and just work in this real domain. If it can't find a real part, I'm okay with just throwing an error; I don't intend it to work for everything, just work for most basic sort of equations.

Gold Member
The Complex i would have to disappear somehow when you take the root, so when you subtract 2, you get 0. I don't see how that can happen.

person123
I realize I had a bug in my code. After fixing it, it does end up converging on 10 (plus 1e-14i, which I can just remove in a machine zero check)!

So in this case, even though I started at 1, which is a complex part of the domain, it converges to the real solution. (As for how I'm performing operations on complex numbers, I'm just using mathjs).

Do you think this would work in general?

jgill
Some years back I wrote a BASIC program to search for zeros of complex functions by using a simple "follow the greatest decline" principle (avoiding the calculus) in searching for a minimal of the absolute value of the complex function. I resurrected it and entered your function and got z=10. Probably no non-real zero as WWGD said.