Fractals in Mathcad

I first plotted the Mandelbrot set on a Spectrum 48k, sometime in my early teens. Writing the code probably took a few hours (hey…I never said I was fast at these things). I left my Spectrum running overnight, chugging away and number crunching. I woke up in the morning to find a highly-pixelated  image of the fractal, plotted in wonderful black and white. I beckoned my sister to witness the mathematical glory I had produced, but she was too busy watching Going Live.

Since those halcyon days, one of the first things I do when I learn a new programming language or maths tool is to plot a fractal (it’s my warped version of  “Hello World”). For example, here’s an earlier Maple worksheet and blog I wrote about the Mandebrot set.

In my time, I’ve plotted Mandelbrot Sets, Julia Sets, Quanternion fractals, Koch triangles and more. However, I always drift back to the Mandelbrot set. The deeper you dive into its complex canyons, the more beauty you discover.

I won’t discuss the mathematics or the algorithms in detail, but here’s part of a Mathcad worksheet that generates the Mandelbrot set (the download link is at the bottom of this post)

The first program generates a matrix giving the number of iterations before each point in the set tends to infinity (i.e  is greater than a bailout value). The second program colours each point with custom RGB values; this is then plotted in a 2D plot.

A Mathcad routine to generate the Julia set follows the same process (again, the download link is at the bottom of this post).

Here’s a few colourful renderings of the Mandelbrot Set and the Julia Set I’ve generated using these Mathcad worksheets.  The colouring algorithm is where much of the artistry comes into play.  Just by tweaking a few numbers, you can produce remarkably different pictures.

These pictures were generated entirely inside Mathcad, with no other image editing.

So what are the downsides of using Mathcad for generating fractals? Mathcad’s an interpreted environment, so compiled C code will always be many orders of magnitude faster. However, a Mathcad worksheet is good for developing the initial algorithms – it’s a much more interactive, easy-to-use environment than a text editor and a compiler. Mathcad gives you much faster feedback on your algorithms than a traditional programming language.

Mathcad Worksheet for the Julia Set

Mathcad Worksheet for the Mandelbrot Set

What do our Customers say about us?

At 13-years old, my daughter’s research manuscript has been accepted for publication in a top tier peer-reviewed Environmental Science journal and OriginPro 8.6 will allow her to export the graphs in a wide variety of formats which can meet any publisher’s requirements. Kudos to OriginLab for designing innovative and intuitive software that can span the needs of both a burgeoning young scientist like my daughter to a PhD expert in their field. It is hard to imagine that other products offer this extraordinary level of user versatility.

Michael Grimmett, MD, FACP, FACS Ophthalmologist Palm Beach Gardens, Florida

The new Quick Fit Gadget is fantastic and I absolutely love that I can output results to a worksheet so that I can get a column of a particular parameter on which I can do statistical analysis.

Greg Scott, University of Illinois at Urbana-Champaign

You have set a benchmark standard that many other companies should aspire to.

JS, Chippenham, UK

THANK YOU – you are a star and have saved my thesis! Your instructions worked perfectly. If I am purchasing upgrades I will definitely go to Adept now I know what level support you can provide.

CB, Plymouth, UK

For the time being we are unable to offer the following product ranges although we are currently working hard to increase the number of products we can offer in the future. Please contact us to talk about alternative products that we may be able to offer you.