Newton-Raphson Method With Complex Numbers

In summary: Yes, the code will find a real root that is "near enough" (for complex convergence) to a real initial guess.
  • #1
person123
328
52
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!
 
Mathematics news on Phys.org
  • #2
person123 said:
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.
 
  • #3
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.
 
  • Like
Likes WWGD, person123 and topsquark
  • #4
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.
 
  • #5
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.
 
  • #6
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?
 
  • #7
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.
 
  • Like
Likes WWGD
  • #8
person123 said:
I guess I'll stick with initially searching for real parts of the domain as @andrewkirk suggested, and just work in this real domain.
@andrewkirk was not suggesting that, he was pointing out that only using the real parts would make it even less likely to converge.

person123 said:
Do you think this would work in general?
Does your code work in general? No idea. A good way to find out if code works is to use unit testing.

Does complex Newton-Raphson find a complex root which is "near enough" (for convergence) to the initial guess? In general yes. What therefore do you think we can say if there is a real root and it lies "near enough" (for complex convergence) to a real initial guess?
 

Similar threads

Replies
8
Views
2K
Replies
1
Views
1K
Replies
13
Views
2K
Replies
9
Views
2K
Replies
3
Views
1K
Replies
5
Views
2K
Back
Top