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?
 

FAQ: Newton-Raphson Method With Complex Numbers

What is the Newton-Raphson method?

The Newton-Raphson method is an iterative numerical technique used to find approximate solutions to real-valued functions. It is particularly useful for finding roots of equations. The method uses the function value and its derivative to predict the next approximation, converging to the root under suitable conditions.

How does the Newton-Raphson method apply to complex numbers?

The Newton-Raphson method can be extended to complex numbers by treating complex functions and their derivatives similarly to real functions. The iterative formula remains the same: if \( z_n \) is the current approximation, the next approximation is given by \( z_{n+1} = z_n - \frac{f(z_n)}{f'(z_n)} \), where \( f(z) \) is a complex function and \( f'(z) \) is its derivative.

What are the convergence criteria for the Newton-Raphson method with complex numbers?

Convergence of the Newton-Raphson method in the complex plane depends on the function and the initial guess. Generally, if the initial guess is close enough to the actual root and the function is well-behaved (i.e., the derivative is not zero), the method will converge quadratically. However, it can also diverge or converge to a different root if the initial guess is poorly chosen.

What are some common applications of the Newton-Raphson method with complex numbers?

The Newton-Raphson method with complex numbers is commonly used in fields such as physics, engineering, and computer graphics. It is often applied to solve complex polynomial equations, optimize functions in complex analysis, and in simulations involving wave functions and other phenomena that require handling of complex variables.

What are the limitations of using the Newton-Raphson method with complex numbers?

Some limitations of the Newton-Raphson method with complex numbers include the possibility of divergence, especially if the initial guess is far from the root or if the function has multiple roots. Additionally, if the derivative is zero at the approximation point, the method fails. Furthermore, the method may lead to cycles or chaotic behavior in certain cases, complicating the convergence process.

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