Course Notes of Peter Staab

This is where Symbolic Computation class notes are found.

Follow me on GitHub

Chapter 19: Newton’s Method in the Complex Plane

Newton’s method works great with complex numbers as well. In short, we just need to start it with a complex number and it will iterate the same way.

(Note: the interpretation of using the tangent line to estimate the root isn’t quite the same as with real numbers, but it still converges to a root.)

Let’s use this to solve \(x^{2}+5=0\), which should have the solution \(x=\pm i\sqrt{5}\). First, define

f(x)=x^2+5

and

df(x)=2x

and if we do newton(f,df,1.0) then the result stays in the real number and we get -11.659358758975838 but this isn’t the solution.

However, if we type newton(f,df,1im), the the solution 0.0 + 2.236067977499978im.

Exercise

The equation \(x^{3}-1=0\) has one real root and two complex ones. Use newton’s method to find all of them.

Finding Complex roots

It is quite interesting to solve \( z^n=1 \) for \(n=3,4,…\) using Newton’s method and we will spend the rest of this chapter doing so. Mainly we will be examining the case where \(n=3\) or finding roots of \(f(z) = z^3-1\).

Creating an picture of newton’s method

The following is quite interesting. Consider the map \(f(z)=z^3-1\) and some initial condition, iterate Newton’s method until it converges. Except \(z_0=0+0i\), it will converge to one of three roots. Label the initial point A, B or C for the roots (or more visually interesting, give the initial point a color). Do this for a number of initial points and see what it looks like.

  1. Start with an array of initial points:
     Z=[x+im*y for y=1:-0.1:-1, x=-1:0.1:1]
    

    This will make a 21 by 21 array of complex numbers. Notice that we did x-im*y to get the numbers to align with the way that we typically think of numbers in the complex plane.

  2. Run Newton’s method with the function \(f(z)\) as above on every initial point:
     roots=map(a->newton(x->x^3-1,x->3x^2,a),Z)
    

    and this returns the root that each initial condition goes to.

  3. Label each root a number. We can do this with the angle command. For example:
     angles = map(angle,roots)
    

    this will return all of the roots in radians, and the following will switch to degrees and round to the nearest integer:

     angles = round(map(angle,roots)*180/pi)
    
  4. There will be a problem with the center point in this array. If we look at:
     data[9:15,8:13]
    

    note that the center (at row 11, column 11) is NaN. This is because we divided by 0 in Newton’s method.

  5. Let’s change the angles to 1, 2 or 3. We will convert the data to an integer array and then do some integer division:
     data2=div(convert(Array{Int,2},data)+240,120)
    

    returns a nice 21 by 21 matrix such that it explains which roots Newton’s method goes to. It is:

     1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  3  3  1  1  2  2
     1  1  1  1  1  1  1  1  1  1  1  1  1  1  1  3  3  1  2  2  2
     1  1  1  1  1  1  1  1  1  1  1  1  1  1  3  3  3  2  2  2  2
     1  1  1  1  1  1  1  1  1  1  1  1  2  2  3  2  2  2  2  2  2
     1  1  1  1  1  1  1  1  1  1  1  3  2  3  1  3  2  2  2  2  2
     1  1  1  1  1  1  1  1  1  1  1  1  3  3  1  1  2  2  2  2  2
     1  1  1  1  1  1  1  1  1  1  3  3  3  3  3  3  2  2  2  2  2
     1  1  1  1  1  1  1  1  1  1  1  3  3  3  1  2  2  2  2  2  2
     1  1  1  1  2  3  3  1  1  1  2  3  3  1  2  2  2  2  2  2  2
     2  1  1  3  2  2  2  2  2  1  2  3  3  2  2  2  2  2  2  2  2
     2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2  2
     2  3  3  1  2  2  2  2  2  3  2  1  1  2  2  2  2  2  2  2  2
     3  3  3  3  2  1  1  3  3  3  2  1  1  3  2  2  2  2  2  2  2
     3  3  3  3  3  3  3  3  3  3  3  1  1  1  3  2  2  2  2  2  2
     3  3  3  3  3  3  3  3  3  3  1  1  1  1  1  1  2  2  2  2  2
     3  3  3  3  3  3  3  3  3  3  3  3  1  1  3  3  2  2  2  2  2
     3  3  3  3  3  3  3  3  3  3  3  1  2  1  3  1  2  2  2  2  2
     3  3  3  3  3  3  3  3  3  3  3  3  2  2  1  2  2  2  2  2  2
     3  3  3  3  3  3  3  3  3  3  3  3  3  3  1  1  1  2  2  2  2
     3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  1  1  3  2  2  2
     3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  1  1  3  3  2  2
    
  6. Using a colormap to create a image. First, if you haven’t loaded these:
     using Images, Colors
    

    then let’s make a color map:

     cmap = colormap("reds",3)
    

    and then

     ImageCmap(data2,cmap)
    

    produces the following: plot of Newton's method in the Complex Plane

  7. There’s actually a problem with this because the way an image treats the underlying data is different that the mathematical way of understanding arrays. (Look at the documentation on the Images package for more info). To fix the picture, if we
       image=ImageCmap(transpose(data2),cmap)
    

    then the result is correct.

Putting this all together