[ v iet- h ung  ng uyen ]

Visualizing Mandelbrot set

December 25, 2022 · 2 min read

Note: This post requires you to have a basic understanding of complex numbers. If you don’t know what complex numbers are, you can read about them here.

Introduction

I love coding, and I also have a passion for mathematics. I’ve always wanted to combine my love of coding and my knowledge of mathematics to create interesting but also educational visualization, something is similar to the works of 3Blue1Brown and The Coding Train.

I’ve always been fascinated by fractals. They are geometric entities with infinite amount of roughness. They have fractional dimensions (not 1D, 2D, or 3D). Among them, Mandelbrot set is one of the well-known fractals. Since the generation process is simple and straightforward, it is a great entry point for people who want to code their own fractal visualizations. However, there are some challenges when rendering fractals in real time.

What is Mandelbrot set?

The Mandelbrot set is a fascinating fractal discovered by Benoit Mandelbrot in 1980. To generate the set, we need series of complex numbers starting from 00 and recursively apply the function f(z)=z2+cf(z) = z^2 + c, where cc is a complex constant.

In general, we have a series of complex numbers

0,f(0),f(f(0)),f(f(f(0))),0, f(0), f(f(0)), f(f(f(0))), \dots

This series will eventually converge to a point, oscillate, or diverge to infinity and depends on the choice of constant cc. If the series diverges to infinity, then the point cc is not in the Mandelbrot set. On the other cases, cc is in the set.

What I use to render Mandelbrot set?

Bonus: The Julia Set

The Julia set is a fractal is the fractal that use the same recursive function f(z)=z2+cf(z) = z^2 + c as the Mandelbrot set. However, the iterative process to generate Julia is quite different from the Julia set. Instead of starting with initial z0=0z_0 = 0 and plotting the constant cc, we would start with arbitrary cc and plot the initial value z0z_0. This leads to different choice of constant cc resulting in different Julia set.