Extending the idea to the complex plane#

Updating the strategy for use of complex numbers is simple.

  • Add the imaginary part.

  • Choose a suitable norm for the convergence criteria.

  • Track some comparable intermediate result for visualization, the real part of the iterands in this case.

Hide code cell content
import ipywidgets as ipw
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
plt.rcParams['figure.dpi'] = 300

def calculate(x, y, max_iterations):
    c = complex(x, y)
    c0 = c
    results = []
    for index in range(max_iterations):
        c = c**2 + c0
        if abs(c) > 10:
            break
        results.append(c.real)

    return results

x_min, x_max = -2.1, .5
max_iterations = 50
resolution = 300

x = [x_min + (x_max - x_min) / (resolution - 1) * index for index in range(resolution)]

Now we need to choose some numbers to fill the imaginary part. Surely we will be choosing these.

ys = [0, .1, .25, .5, 1, 1.25, -.25, -.1]
Hide code cell source
tabs = ipw.Tab()
children = []
for _y in ys:
    y = [calculate(_x, _y, max_iterations) for _x in x]
    
    with plt.ioff():
        output = ipw.Output()
        with output:
            fig, axes = plt.subplots()
            for _x, __y in zip(x, y):
                __x = [_x for _ in __y]
                axes.plot(__x, __y, "b.", markersize=1)
            axes.set_ylim(-2.2, 2.2)
            axes.set_title(f"y={_y}")
            plt.tight_layout()
            plt.show()
            children.append(output)

tabs.children = children
for index in range(len(children)):
    tabs.set_title(index, f"y={ys[index]}")
    
tabs

The behaviour is quite comparable to what we’ve seen for plain real numbers.

Still, the overall pattern is not directly visible, as the effect of the imginary part is missing in the plots.

Again, we need a different strategy.