Why does the Mandelbrot fractal appear when plotting $\underbrace{x\cos(x\cos( \cdots x\cos}_9(x))))$?

376 Views Asked by At

enter image description here

while plotting the function $x\cos(x\cos(x\cos(x\cos(x\cos(x\cos(x\cos(x\cos(x\cos(x)))))))))$ using matplotlib in python I found the mandelbrot fractal.

What is the reason that the mandelbrot fractal appears in the process and what literature should I read to learn more about this. Maybe the mandelbrot fractal appears in more places where you iterate a function over and over again. here is the code

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import cmath

# Defining the function to map a complex function
def map_complex_function(complex_func, real_range, imag_range, color_scheme=("magnitude", "argument", "(10x)/(10x+1)")):
    # Creating the domain
    real_values, imag_values = np.meshgrid(np.linspace(real_range[0], real_range[1], 1000),
                                           np.linspace(imag_range[0], imag_range[1], 1000))
    z_values = real_values + 1j * imag_values

    # Applying the complex function to the domain
    w_values = complex_func(z_values)

    # Extracting the magnitude and argument
    magnitude = np.abs(w_values)
    argument = np.angle(w_values) / (2 * np.pi) % 1

    # Determining brightness based on the provided color scheme
    if color_scheme[2] == "(10x)/(10x+1)":
        brightness = (10 * magnitude) / (10 * magnitude + 1)
    else:
        brightness = magnitude / np.max(magnitude)

    # Creating HSV values
    saturation = np.ones_like(argument)
    hsv_values = np.stack([argument, saturation, brightness], axis=-1)

    # Converting HSV to RGB
    rgb_values = mcolors.hsv_to_rgb(hsv_values)

    # Plotting the image
    plt.imshow(rgb_values, origin='lower', extent=[real_range[0], real_range[1], imag_range[0], imag_range[1]])
    plt.xlabel('Real part')
    plt.ylabel('Imaginary part')
    plt.title(f'Complex map for {complex_func.__name__}')
    plt.colorbar(label='Magnitude (custom scale)')
    plt.show()

def f(z):
    return z*np.cos(z*np.cos(z*np.cos(z*np.cos(z*np.cos(z*np.cos(z*np.cos(z*np.cos(z*np.cos(z)))))))))
    
# Creating the plots
real_range = (0, 6)
imag_range = (-4, 4)
map_complex_function(f, real_range, imag_range, color_scheme=("magnitude", "argument", "(10x)/(10x+1)"))```
1

There are 1 best solutions below

0
On BEST ANSWER

Fix some $z_0$, define $f(z) = z_0 \cos(z)$, and let $$ f^n = \underbrace{f\circ f\circ \dotsb \circ f}_{\text{$n$ times}}.$$ Given some point $z_0 \in \mathbb{C}$, the pixel corresponding to $z_0$ in the image is assigned a color based on the value of $f^n(z_0)$ (where $n$ is whatever you choose it to be—in the question, it seems that $n=11$ish). The precise details aren't all that important—the relevant bit is that if $|f^n(z_0)|$ is large, the corresponding pixel is dark; and if $|f^n(z_0)|$ is small, then the color of the corresponding pixel is determined by the argument of $f^n(z))$ (more or less). The image in the question is obtained by taking $n\approx 10$ (maybe a bit bigger? I didn't count all the cosines).

Similarly, fix $z_0$ and define $g(z) = z^2 + z_0$. Applying the same coloring scheme to points in the complex plane, $g^{n}(z)$, for some largish value of $n$, looks something like

enter image description here

This image was created using Will Bolden's Complex Function Visualization tool. Here is a link to the configuration which gives the image above, perhaps modulo some checkerboard patterns and/or markers for zero). Note that this is an approximation of the Mandelbrot set.

The visualization of $f^n$ has copies of things which look like the Mandelbrot set because $f$ looks a lot like $g$ for certain values of $z=z_0$. This can be seen by considering the Taylor series $f$ at $a=2k\pi$ (where $k\in\mathbb{Z}$):

\begin{align} f(z) &= z_0 \cos(z) \\ &= \pm z_0 \sum_{n=0}^{\infty} (-1)^n \frac{z^{2n}}{(2n)!} \\ &= \pm z_0 \left( 1 - \frac{(z-a)^2}{2} + \frac{(z-a)^4}{4!} - \frac{(z-a)^6}{6!} + \dotsb \right) \\ &\approx \mp\frac{(z-a)^2}{2}z_0 + z_0 \\ &= C (z-a)^2 + z_0, \\ \end{align} where the leading sign (the $\pm$ and $\mp$) depends on the parity of $k$, and the value of the constant $C$ will depend on the choice of $z_0$. For any fixed $a$, this function looks a lot like the function $g$, which generates the Mandelbrot set. This implies that the behaviour of $f^n(z_0)$, when $z_0 \approx 2k\pi$ for some integer $k$, should "look like" the behaviour of $g^n$ around zero.

As such, I would expect to see a little "mini-Mandelbrot" around every integer multiple of $2\pi$ on the real axis. Moreover, I would expect that they will alternate between two colors (in the original image, I'm guessing teal, which corresponds to the positive real axis; and red, which corresponds to negative real axis). Finally, the bigger $|z_0|$ is, the larger that leading constant will be, which will make it "harder" for iterates to remain bounded. Hence I would expect the "mini-Mandelbrots" to get smaller and smaller as they get farther from the origin.