Friday, 24 October 2014

LinuxVoice Magazine

I'm really pleased that LinuxVoice Magazine has published the first of my 2-part series on Python and the Mandelbrot fractals.

I hope the series will inspire those completely new to programming to try it - the tutorials require no previous experience at all.

And I also hope the mathematics - which is no more difficult than school maths - will inspire young and old by showing that it can be surprising, exciting and beautiful!

I'd like to thank Graham, the editor of LinuxVoice, for being so accommodating, helpful and patient with me.

By the way, I've been reading computer magazines for over 20 years and LinuxVoice has refreshed enthusiasm, community spirit, and quality content - best wishes for its future!

Grab a copy of issues 009 and 0010 - out now and next month!

Saturday, 27 September 2014

Oil Painting Fractals

I was exploring artistic filters in image editing software - you know the kind that make an image look like it was really sketched with an ink pen or painted in watercolours.

The usual software wasn't doing it for me because the effects looked very fake, so I explored further and found the free FotoSketcher. Its focus is purely on such effects - and it's brilliant. I particularly like the Painitng 5 (watercolour) and Painting 6  (oil) effects - they are very realistic.

Then it struck me - what if I applied these filters to fractal images? The results, in my opinion, are fantastic! Enjoy .... and do try it yourself!

Wednesday, 27 August 2014

Pure Web Mandelbrot Explorers

I love tools that are purely web based.

The benefits are huge - you don't need to install any software, the software is automatically updated by the supplier, it works across any operating system or device or brand as long as it supports modern open web standards. You can carry on working between devices, from different location, and you don't lose your work if your local device breaks.

You can do quite a lot with pure web technologies - Google's office productivity suite is a great example, so is's IPython in the cloud.

You can explore the Mandelbrot fractals purely with a web browser too.

I love the following tools I discovered recently:

Tuesday, 26 August 2014

The Complex Plane And Plottable Arrays

Some readers have asked me to explain the slightly complicated translation between the complex plane (where the Mandelbrot set really lives) and the Python arrays used to plot the images.

The reason for the complexity is that:
  • The complex plane is continuous, just like the real number line.
  • Python arrays are discrete, filled with finite boxes. 
  • What's more, the elements of python arrays are labelled using integers starting from zero. You can have array[2, 3] but not array[-2.34, +4.3398]. 
  • We have to plot arrays, even though we really want to see the complex plane. This is the core reason we need to translate between the complex number plane world, and the python array world.

The translation itself is simple. We divide up the complex plane into equally spaced and sized sections. There are an integer number of these - and so they can be represented by the elements of an array.

So when we choose an element n out of N along a section which started at x1 and ended ay x2, the element n corresponds to x1 + (x2-x1)*(n/(N-1)). You can see here that n/N is the proportion between x1 and x2 that n lies.

If this expression looks complicated to you - it's just working out how far from x1 towards x2 we need to go in the same proportion as n out of N pieces.

Ah - and don't forget n starts at 0 and ends at N-1, which makes sense so that when n=0 we have the position x1. Similarly when n is the last N-1,  it corresponds to x2.

The following diagram shows our explanation visually: (click to enlarge)

The Deep Connection Between Julia and Mandelbrot Fractals

The Julia and Mandelbrot fractals are intimately connected.

They are both generated by iterating the simple function z2 + c.

For the Mandelbrot set, z starts as the value of the point being tested on the complex plane, and c is zero. In effect the function becomes z2 because c is zero.

For the Julia sets, c is set to a contant value throughout all the calculations. In thisway, c uniquely defined that particular Julia fractal. That same c always generates that same pattern.

If you've explored the Julia and Mandelbrot sets, you may suspect that there is a connection between the two. In fact there is:

  1. Julia sets whose unqiue c value falls inside the Mandelbrot set are connected - that is, they are all one piece.
  2. Julia sets whose unique c value fall outside the Mandelbrot set are not connected - that is, they consist of many disconnected pieces. 
  3. Julia sets whose c lies further away from the Mandelbrot set have greater fragmentation, until they become almost dust like.

The following digram summarises this deep connection: (click to enlarge)

Saturday, 9 August 2014 for PyData London Meetup

I'll be presenting a five minute flash presentation on Make Your Own Mandelbrot on the 2nd September for the London PyData Meetup.

A perfect excuse to try out alternative slide presentation tools!

Prezi was nice but it's expensive. Impress.js is flexible but not great if you don't want to hand edit code. is great! Easy, beautiful, and with a free option too.

He's the current iteration:

Saturday, 2 August 2014

Home Schooling

I was pleased to hear a friend of mine bought the Make Your Own Mandelbrot ebook to  inspire his child who was struggling to be excited by mathematics.

He hoped that the easy, conversational, approach and the connection with unusual behaviours, and some fantastic images would excite his secondary school boy.

He also hoped the introduction to Python would ease the path into computer literacy, addressing a fear of the "technical stuff that happens under the hood". I found this suprising because most boys, including this one, were avid computer and games console users - but upon reflection that is different from playing with programming and electronics, and ultimately computational thought.

I wish him well and I hope others will too! The summer holidays are an ideal time to play with mathematics and computer programming in a fun recreational way, and not have the pressure of any teacher marking your work!

Sunday, 20 July 2014

Errata #1

Thanks to the generous person who submitted the following error in the ebook.
It is in the section on mathematical operations on complex numbers.

In the book (a + bi) + (c + di) = (a + b) + (c + d)i
Should be (a + bi) + (c + di) = (a + c) + (b + d)i

In the book (a + bi) – (c + di) = (a - b) + (c - d)i
Should be (a + bi) – (c + di) = (a - c) + (b - d)i

I'll update the ebook asap and you should be able to request Amazon Kindle to get an updated version at no extra cost. I understand the updates aren't always automatically pushed out by Amazon.

UPDATE: Amazon Kindle ebook is now updated with this correction.

Thursday, 17 July 2014

CreateSpace Paperback

Make Your Own Mandelbrot is now available as a paperback from CreateSpace. You'll be able ot get paperbacks from Amazon soon.

Thanks for the feedback from those of you who prefer a real book in your hands over a glowing electronic thing!

Wednesday, 2 July 2014

Google IPython?

IPython is great.

It's a full Python, with many of the most useful and popular extensions for numerical computing and visualisation.

For many, it is the place to do both Python programming, numerical computing and data science.

Even better, IPython can be pure web. That is, you can work with it, fully and interactively,  using only a modern web browser. No need to install and configure any software at all. This is immensely powerful, because you can keep your work in the cloud, leave and carry on at a later time from any device with a browser, be that a laptop or a tablet, or even a smartphone.

Now imagine Google with its vast compute and storage resources offered an IPython service. That would be an immensely powerful combination.

And Google could. They love Python, their App Engine runs it. There's a "numerical compute and cloud programming" gap in their web app range.

Plus they'd love the social sharing of IPython notebooks.

When, not if?

Raspberry Pi for Younger Learners

The Raspberry Pi is perfect for younger learners. It's simple, cheap, fun and a great way to learn about computer hardware and programming. For all these reasons the Pi is increasingly popular in schools and for home education.

The Raspberry Pi, and much of tutorial ecosystem around it, promotes Python as an ideal programming language - and quite right too!

I intend to get a Pi for my own child, and will confirm that the content of the ebook works, and I'll explain any special steps you have to take to install IPython, if any at all.

Of course, you're still encouraged to use the cloud based IPython, from for example, because all you need is a browser, with no need for software installation of configuration.

Perfect for the Pi!

Saturday, 21 June 2014

Mindmup: Organising Your Thoughts

Whether you're writing a book, code, or a school essay, I really recommend visually planning out your thoughts.

The problem with pen and paper is  that correcting and re-arranging your ideas gets messy, and defeats the original idea.

There are many software tools to do mindmapping, and honestly, the few that I've tried have been more of a pain than a help.

I recentl found mindmup. I love it! And recommend it. It's free. Open source. Works with Google Docs seamlessly. Exports useful formats like PNG and PDF.

And more to the point, it is really friction free. For me it has been the best tool, just stays out of the way like a good tool should.

Sunday, 8 June 2014

Complex Numbers Are More Complete Than Reals

We've previously explained what complex numbers are, and how to work with them.

What we perhaps didn't explain so clearly is why we need complex numbers. Sure they've turned out to be very very useful for simplifying calculations about the real world, but what's a good motivation for them?

A great explanation came from this fantastic book: Elliptic Curves.

The book itself aims to do what Make Your Own Mandelbrot wants to do - share some of the most  amazing and beautiful mathematics to as wide an audience as possible by taking readers through the concepts gently using clear English. I've just finished Chapter 2 and I can't wait to get through the rest of it.

Anyway, this book's explanation is super simple:
  1. It is nice to have a system of numbers, or things like "numbers" where a set of operations (like add, subtract, multiply, divide) on any of these numbers results in numbers that are also in the same system.
  2. The normal number system we all learned about at school, and use everyday, seems to be complete in this sense. That's the system of "reals" such as 1.0, 3.44, -5.6, 999.22 and so on. We can add two of these numbers and the result is also in this system.
  3. The problem arises when we look at polynomials whose coefficients are also taken from this same system, the real numbers. We would like the roots of these polynomials to also be found within this same system of reals. The polynomial (x-1)(x+2)(x-3) has roots that are x=1, -2 and 3. But some polynomials like x2 + 1 don't have roots from the real numbers. 
  4. So we have to extend the real number system so that these polynomials have roots that are always within the extended number system. That extended number system is the complex numbers (a+bi).
  5. The nice thing about this system that we appear to have invented is that polynomials with complex coefficients, always have roots also in the set of complex numbers. This now means we have a more "complete" system. The real numbers weren't complete (algebraically closed) in this sense - polynomials built from real coefficients sometimes didn't have roots in the real numbers.

I'm really excited by this super clear explanation. Why don't more authors do this?

Anyway, here's a summary:

Friday, 6 June 2014

(Fixing) Kindle Ebooks Wth Google Docs

There are many tutorials out there on making ebooks. The truth is that right now there are no good tools, the technical file formats for ebook are not great, in flux, and on top of this not well or consistently supported. Even lots of money won't buy you good tools - the Adobe Indesign plugin doesn't magically transform your works of art into perfect ebooks.

I used Google Docs (now called Drive) to type my material, and insert diagrams and images. I did use titles, headings, subtitles to give the documenty some structure. The great thing about Google Docs is that it's free, accessible from almost anywhere with no need to install software, ... very convenient and efficient. Your content in Google Docs can be exported in a range of useful formats, including Microsoft Office, ODF, PDF, and HTML.

The steps for making a Kindle ebook is simple:
  1. Export your doument as HTML. This will give you a zippled folder with the content and any images that you used.
  2. Import the main HTML document into Sigil. Use Sigil to add a cover, book metadata such as title and author, and contents. You might like to split up a long document into separate HTML sections. This is also your opportnity to clean up the content, remove additional spaces, blank lines, centre things that weren't.
  3. Export an epub from Sigil. This is an open file format for ebooks, and quite well supported by many readers but not perfectly, as I said above. 
  4. Amazon doesn't like epubs so they convert it to their own format when you upload it to their site.
Note that I didn't use the Calibre software much recommended. I suspect that as Sigil is not actively developed, I will eventuallyhave to learn to use Calibre. My experiments with it weren't great - all the epubs I could get out of it were not as good as the straight HTML to epub conversion by Sigil.

You might want to use preview tools to check your epub file works and get an indication of what it might look like on real physical readers.

Just this week I fixed an annoying problem which seemed to only affect Android Kindle readers which seemed to force very wide margins, meaning the content was squished into a very thin column. The usual internet search led to messing about CSS styles to override the margin, border and padding settings. It didn't work. The answer was actually to go back to the Google Docs document and use the page setup menu to zero the page margins...voila! That worked!

Hope this helps someone else.

Sunday, 1 June 2014


Thanks for the feedback on the Make Your Own Mandelbrot ebook - keep it coming.

So far the main requests have been:
  • A super simple walkthrough of working with complex numbers with clearer examples. Perhaps as an Appendix.  Someone also asked why we avoided talking about dividing complex numbers.
  • A discussion of why the 3D section extends the 2D fractals into 3dimesnions but doesn't actually use 3D versions of complex numbers. It seems that several readers have naturally asked the question we discussed in a previous post. 

Great ideas! I think a second edition is starting to form ...  And please do keep your suggestions coming in, they all contribute to an even better second edition.

Saturday, 31 May 2014

Colouring The Inside #2

And taking the idea of the last post to Julia sets produces some wonderful images.

Try it yourself with Xaos!

Friday, 30 May 2014

Colouring The Inside

The most common visualisations of the Mandelbrot set have the set itself coloured black, and the regions outside coloured. The colouring scheme usually reflect how quickly the points outside the set diverge.

But what would happen if we applied similar logic to colouring the inside of the set, and left the outside black?

The following images show the results. They provide an interesting insight into the dynamics of the set. It's a perspective you don't often see.

 You can create these yourself using Xaos by setting the in-colouring and out-colouring options.

I personally love the liquid metal look of some of the images!

Monday, 26 May 2014

Last Interview with Benoit Mandelbrot

The last interview with Benoit Mandelbot himself, who disocered the Mandelbrot Set and coined term fractal.

Benoit is much respected for having the determination to explore outside the mainstream, and it paid off.

Saturday, 24 May 2014

Beautiful BBC Documentary on Fermat's Last Theorem

The BBC has put up some of its best Horizon documentaries online to watch again.

I would recommend everyone to watch the beautifully made, and at times, emotional documentary on Fermat's Last Theorem and Andrew Wiles' jounrey to crack it.

The BBC does a fantastic job of giving us a taste of the stunning simplicity of the Theorem, the intricate battles of mind and will to prise open insights and make connections across the fields of mathematics, and the very human travails. The story of a quiet unassuming man who hid a determination and passion to solve the deceptively simple Theorem that had eludes so many for so long.

Inspiring! I'd recommend all students watch it!

If you can't receive IPlayer, because you're outside the UK, there's a version on YouTube too:

Thursday, 22 May 2014

Sunday, 18 May 2014

Complex Numbers Explained

Impenetrable Jargon

I really displike how too many thngs in mathematics are not explained clearly and simply. Too often really cool things are kept out of the reach of normal people - because the explanations are written in some alien inaccessible language.

What the mathematics community need to realise is - writing stuff in a language only a few of them understand is not big and it's not clever. I'm not impressed.

What is clever - what is hard - is being able to explain those ideas so that the maximum number of people can understand and appreciate them. That should be the measure of success.

If research grants and teaching salaries were based on this measure I wonder how quickly the profession, and the texts it publishes, would change?

Anyway, I'm going to try to demystify complex numbers.

Complex Numbers Are Not Complex

Complex numbers are not complex. That's a really unfortunate name which scares people. It's an accident of history. They should have been called composite or 2-part numbers, or anything that doesn't put barriers up straight away.

Normal numbers, like 2, 3, 4.5, 9.332 are 1-dimensional. That is they describe one thing and only one thing. They could be the length of a rope, or the time it took to finish a race. They can't describe two things at the same time. That is, you can't use a single 1-dimensional number to describe both the width and length of a swimming pool - you have have to have two numbers, one for the width and one for the length.

Complex numbers are 2-dimensional. They have 2 parts. These two parts are independent of each other. One part can do what it likes and is not in any way influenced or constrained by the other. The two parts of a complex numebr are like apples and oranges. You can't mix them up, an apple will always be an apple and not an orange. This is an important thing to keep im mind when we combine complex numbes later.

The following shows the two parts of a complex number. They just happen to be called the real part and the imaginary part. Again, don't let these names put you off, they have been settled on without anyone really considering the best names for these parts.

We could have written these two parts in a different way. For example, (2,3) or (2,3i) or (3i,2) or even (3i+2) ... but the convention is (2+3i) and sometimes without the brackets when it is clear enough what we mean 2+3i. Again, this is just a convention that we arrived at through history becuase it worked well for lots of people. If you are an engineer, you may have seen the symbol j used instead of i. That's ok becuase those engineers often use i to mean other things - they use j to avoid ambiguity. So they might write (2+3j), but most people use i.

What are these numbers good for? Well they are in fact really useful for lots of things in science and engineering, not just for making fractal images!

For now let's just notice that these 2-part complex numbers are very similar to coordinates locating points on a flat 2-dimensional surface. Just like a map grid reference or the familiar (x,y) coordinates when we work with graphs. We can in fact think of comlex numbers as points on a flat surface becuase they have two independent parts. Look at the following diagram and you'll see they aren't that different to the normal (x,y) coordinates for points on a graph.

The first diagram shows the complex number (3+2i). You can see the horizonal distance is 3 and th evertical distance is 2. This is just like (3,2) on the more familiar (x,y) graphs. The second digram shows (-2-2i) which is just like (-2,-2) on (x,y) graphs.

Ok so complex numbers can very easily represent points on a flat surface, just like (x,y) graph coordinates.

That was easy enough!

Add, Subtract, Multiply with Complex Numbers

What about the normal rules of arithmetic? Adding, subtracting, multiplying? Do they make sense for these strange objects we seem to have invented called complex numbers? Let's deal with adding and subtracting first because they are really easy.

Adding complex numbers is really really really easy! Remember when we said the real and imaginary parts of a complex number are like apples and oranges. We said that these were independent because and you can't change an apple into an orange, and the number of apples doesn't influence the number of oranges at all. Well that's really handy. Because if we want to add two complex numbers we simply add up all the apples from the two numbers to tell us how many apples should be in the answer. The same for oranges. Another way os saying this is that we combine the real and imaginary parts separately.So (2+3i) added to (4+5i) means we combine the 2 and 4 (real parts) and also combine the 3 and 5 (imaginary parts). The answer is (6+8i).

If you're still struggling, think of adding the 2 apples to the 4 apples to make 6 apples. Then adding 3 oranges to the 5 organges to make 8 oranges. These are the two parts of the answer:

(2 apples, 3 oranges) + (4 apples, 5 oranges) = (6 applies, 8 oranges)
(2 + 3i) + (4 +5i) = (6 + 8i)

TIP: Did you know that Google can do maths with complex numbers for you. Try it! Type (2+3i) + (4+5i) into the Google search box and you'll get the answer!

What about subtraction? It's the same. You combine the independent real and imagines parts by subtracting them instead of adding them. Or if you prefer, you subtract the apples, then you subtract the oranges. So (2+3i) - (4+5i) = (-2 -2i). Yes, these have negative parts because 2-4 is -2, and 3-5 is also -2. Again Google can do this too.

Actually this is just like adding and subtracting the familiar (x,y) coordinate vectors if you know about those already.

What about multiplication? This is again just like the normal maths that we know, exceot for one tiny special difference. In fact, to make sure no-one is put off by special differences, we'll tell you know that this single tiny difference is the ONLY difference you need to know about. Once you get it, there are no more hidden suprises later on. That single difference is the only thing you need to remember when working wih complex numbers

So how do we multiply complex numbers? Well remember the familiar matrix multiplication? Multiplying (a + b) by (c + d) was done my multiply each combination of things inside the brackets. So to make the answer you'd have to work out a*c, a*d, b*c and b*d ... and once you'd done all t he laborious work you'd collect terms that were similar.

Let's illustrate this with an example (2x + 3y) * (4x + 5y). We've chosen to include x and y bits because of we didn't the example would be too easy and not illustrate collecting like terms: (2+3) * (4+5) is just 5*9 which is just 45. So let's expand those brackets out. The bits we will collect are 2x*4x, 2x*5y, 3y*4x and 3y*5y. Nothing new here, just what we would normally do. Do the multiplications and we get 8x2 + 10xy + 12xy + 15y2. We have collected all the similar terms yet, there are "xy" bits. Once we've tidied it all up we get 8x2 + 22xy + 15y2. Notice there are 3 kinds of animal here, the x2 bit, the y2 bit and the xy bit. We can't simplify any further because the xy bit can't become x2 as  they are indepdnent different animals - just like apples and oranges are independent.

Noe let's do this familiar multiplication of brackets with complex numbers. Let's try (2+3i) * (4+5i). The answer will have to have the combinations 2*4, 2*5i, 3i*4 and 3i*5i. Lets do the multiplications to get 8 + 10i + 12i + 15i2. Let's carry on tidying up by collecting the similar terms to get 8 + 22i + 15i2. This just like the example above which used x and y instead of real and imaginary parts - that's why we get the same numbers 8, 22, 15.

So (2+3i) * (4+5i) gives 8 + 22i + 15i2. But we don't stop there. That one single special rule we mentioned for complex numbers allows us to replace the i2 with something simpler.

The rule is i2= -1.

So i*i an always be replaced by -1. You don't have to but it helps simplify the expressions. This is a bit magical - combining two imaginary bits creates a real bit. The oranges multiplied together became a negative apple!

Before you think complex numbers will have all sort os such crazy exceptions and rules - stop worrying now. That's the only rule you have to know - and it's really easy to remember.

So if we apply it to the expression we replace 15i2 by -15 .... to get the final answer: (2+3i) * (4+5i) = 8 - 15 + 22i or more simply (-7 + 22i). Again you can check with Google.

That's it! Easy peasy!

We didn't do division because it's just a tinsy bit more complex in terms of messing about with algebra and doens't introduce new ideas, so we left it out to avoid distraction.


You can find a fuller explanation, slower in pace, and with more examples in the ebook.

Friday, 16 May 2014

Python: Smallest Jump from Idea to Code

In Make Your Own Mandelbrot we chose Python as the computer language to learn, and then use to calculate and plot the fractals.

There are many reasons Python is good for you to learn.

Python is easy to learn, and you can get quite far with it before you start hitting advanced or difficult concepts. But most people don't get to that point, and don't need to. Becuase the big chunk of Python that most people learn is more than enough to do useful things with.

Python has a huge following. And it is very popular. You'll find it in games, application servers, and powering huge global infrastructures. It's particularly popular in the science and data fields.

The new wave of children learning computing using the Raspberry Pi are programming in Python.

But for me, there is one special reason I love Python. And I hope you'll love it too for the same reason.

For people who are lucky enough to be able to program in several languages, Python is often the first one used to try out an idea or make an early prototype.

Why is this? It's because the leap from human idea to computer code is often smallest with Python.

The leap from human idea to computer code is often smallest with Python.
 Too many other languages have barriers between your idea and code, stuff that gets in the way, distracts you from just trying your idea. Fragile syntax, special rules that trip you up, lots of boilerplate code that you seem to have to type agan and again. Python mostly stays out of the way.

Just for fun, here's a family free of languages from O'Reilley. It's a little old but still interesting. You can see Python's parents and cousins!

Tuesday, 13 May 2014

Animated Dive Into The Mandelbrot Fractal (XaoS)

A really good fractal explorer that I recommend in the guide is XaoS. There are amy good ones, and many that are free and open source, so what's so good about this one?

XaoS is free and open source, and runs on a variety of operating systems (Windows, Mac OS X, Linux, BSD, DOS and more). You can get it from here.

It is fast - but so are many others.

What XaoS is really good at is zooming into the Mandelbrot fractal so fluidly that the effect is an animation of you fluidly diving deeper and deeper.into the fractal with detail appearing without a glitch. See for yourself with the following videos.

This is actually amazing, given how computationally intensive it is to calculate just one frame of such a video. I recall how in the 1980s it took hours on a home computer to calculate even a low resolution single frame.

Saturday, 10 May 2014

I Will Not Let An Exam Result Decide My Fate

I am passionate about teaching, sharing, mentoring, imparting knowledge, wisdom, and an ability to think and learn yourself.

Some recent feedback from the teaching community got me thinking much more about teaching children by meeting them where they are. Not preaching down to them from some
irrelevant podium of outdated assumptions.

I came across this stunning piece by Spoken Words, called I Will Not Let An Exam Result Decide My Fate.

I urge all teachers to listen and reflect. These are young people extremely eqolouently expressing the gaping holes of education models, measures of success or capability, the dangers of lazy adherence to outdated notions of worth. They davastate our assumptions.

And this is an opportunity to reconnect, not to get defensive and tell them they're wrong. Reconnect because they have shown what needs fixing.

They want and love education, just not our teaching.

Friday, 9 May 2014

Works Even on Monochrome Kindle Readers

I went into a shop to see if the book worked well on an old monochrome Kindle reader. It did!

Wednesday, 7 May 2014

The Mandelbrot Recipe

Sometimes you just want the recipe for making a Mandelbrot fractal, presented in easy to understand steps, with a diagram illustrating how it all works. Here it is... click on the image to get a fuller view.

1. Pick a rectangle on the complex plane.
If you select the rectangle with bottom left corner at (-2.25 -1.5i) and top right corner at (0.75 + 1.5i) you’ll get a good view of the Mandelbrot set. If you chose a rectangle that’s far away from the centre of the Mandelbrot, or is completely within the set, then you won’t see anything interesting.

2. Each point in this rectangle is a complex number representing c, the parameter of our iterated function.
You should pick a reasonable number of points, evenly spaced out. Too many and you’ll have lots of unnecessary calculations to do without adding much detail. Too few points and you’ll have gaps in your plot and insufficient detail.

3. For each of these points, c, iterate the function z2 +c many times.

The complex number z starts at zero, or more properly (0 + 0i). Keep a note of the completed iterations.

4. Stop iterating when either (i) you’ve reached the maximum number of iterations you’ve set yourself, or (ii) the magnitude of the function output grows more than four.
If the magnitude grows greater than 4, the point has diverged and you don’t need to keep calculating further iterations as they’ll diverge further, and may even grow so big as to cause an error in your calculator or computer.
If you’ve reached the maximum iterations, the point c very likely doesn’t diverge.

5. Colour the point c using the number of iterations reached to indicate either (i) the rate of divergence, or (ii) non-divergence for points within the set.
Remember that we have an upper limit on the number of iterations. If it is reached then the iterations did not diverge and so the point is likely to be within the Mandelbrot set. If the iterations are prematurely stopped because the magnitude of z has broken the limit we set of 4, then the orbit does diverge, and the iteration count we did reach indicates how slow or fast the divergence happens. A small iteration count means a rapid divergence.
You could chose other colouring schemes if you wanted to experiment.

Monday, 5 May 2014

Teaching Mathematics

I had an interesting challenge from the teaching community for which I'm grateful. I want to thank the person for taking the time to share his/her views.

It was suggested the guide too easily calls the work children must do as "boring" and that this is unhelpful.

I agree we shouldn't disparage the hard work children must do to pick up the skills they'll need in later life. Multiplying out brackets is important. So is trigonometry.

But I think tihs challenge - gratefully received though it is - misses the point slightly. That the vast majority of people don't associate mathematics with words like "exciting", "beautiful", "surprising".

I was very lucky - extremely lucky - to have had some teachers and mentors who encouraged me to see beyond the rigmorale of mathematics as it was presented to me all those years ago - and to investigate genuinely cool things like fractals, chaos, the golden ratio and fibonacci series in nature and art, the mystery of prime numbers.

My challenge back is this - if you can make trigonomtry something truly exciting, and make matrix multiplication something children look forward to - then you're doing the right thing, and I have a lot to learn from you.

Sorry to but it so bluntly - but it is NOT good enough to drag the kids through the core material whether they like it or not. We can and must be more ambitious. The problem is not with kids not beign interested or appreciating mathematics. It is the teaching.

Saturday, 3 May 2014

Kindle ebook FREE for 1 day!

Get the "Make Your Own Mandelbrot" kindle ebook FREE for 1 day, tomorrow Sunday 4th May.

Grab it while you can!

Thursday, 1 May 2014

Twitter @myomandelbrot

We're now on Twitter too .. come join the discussion @myomandelbrot

And an excuse to post a great 3D image developed using super simple Python code developed in the guide.

Tuesday, 29 April 2014

Book Links - UPDATED

Summary of links to the ebook:

UPDATE - I've enrolled the book in Amazon's KDP Select so it'll be offline from Google and Nook for 90 days.

Saturday, 26 April 2014

Animated Journey Deep Into the Mandelbrot Set

There's a great video on vimeo animating an interesting journey down into the very deep depths of the Mandelbrot set.

The music is great too - really makes it an atmospheric mystical voyage!

Thursday, 24 April 2014

Now on Nook

The book is now also on Barnes and Noble's Nook store.

They have a file size limit of 20MB so the epub had to be shrunk a little, I hope the smaller image files aren't noticeably different.

Wednesday, 23 April 2014

Sharing the Code

I was asked to share the source code so that readers wouldn't have to type it all in themselves, something that potentially introduces errors.

I've shared the IPython notebooks so you can view and run them, and copy the code as you please.

  Mandelbrot fractal: notebook
  Julia fractal: notebook
  3D Mandelbrot lanscape: notebook
  3D Julia landscape: notebook
  Sobel image filtered Julia set: notebook

Have fun!

PS. I remember the old days of typing in code from computer magazines yelllow pages, puzzling over the typing errors, and learning quite a lot from doing it actively. I'd still recommend you follow the discussion in the ebook.

Writing for a Computer Magazine

I'm writing the magazine articles as a 3-part series. It's a real challenge to squash down the size of the books content to 3 sets of 2400 words, the book itself wasn't too florid in it's language.

More challenging is trying to move away from the clear 3-part structure of he book (concepts, DIY, extensions) to 3 articles which must all contain significant elements of programming because the magazine which might publish them is a computer magazine. You can't ask readers to read an entire article on mathematics and wait another month before starting any Python.

So I think this will have to have programming using IPython as the primary focus, with the exciting mathematical journey taking a less prominent role. Sigh....  the sacrifices!

Monday, 21 April 2014


Despite months of writing and checking, and rechecking, it turns out that someone else who does proof reading for you will spot things that you've become blind to!

As a result I'll issue an updated ebook to Amazon and Google. If you've purchased the books already you should be able to get updates automatically at no extra cost.

As ever, if you make significant contributions to the book, you'll get the next edition free.

UPDATE - I've updated both Amazon and Google's stores with the latest round of corrections. I'm trying to get the book into Barnes and Noble's Nook store too.

Tuesday, 15 April 2014

Book is now on Google

The book is now on Google Play Books too.

It's the PDF exported from Google Docs, because the custom built PDF I was designing was taking too long.

Friday, 4 April 2014

Book Published on Amazon Kindle

The first edition of the book is out!

Make Your Own Mandelbrot [Kindle Edition]

I could have gone on forever fixing and tweaking to the nth degree, so I pulled the trigger as soon as I thought it was good enough.

Please do feed back your opinions, corrections, requests for further explanations. If you're particularly helpful I might give you a copy of the updated edition for free!

I have been disappointed with the whole epub/mobi formats and the quality and varitation in rendering across devices. Google bookshop does allow PDFs which you have much greater control over .. so I'm lookign forward to doing some nicer design for it.

Wednesday, 19 March 2014

Magazine Articles

A magazine has expressed an interest in doing a 3-part series covering the same themes as the book.

This is great and I hope will widen the audience - more people appreciating the magic of the Mandelbrot set and it's quite exciting mathematics can only be a good thing.

The challenge will be change from the book's 3 part structure (maths, code, more ideas) into a different form which introduces the coding right from the start. Understandably this is needed to ensure the articles remain relevant to the primairly computing audience.

Thursday, 13 March 2014

Book Cover

Working on the book cover and have settled on a broad design. Click on it to enlarge.

All done with free opensource software -  the graphic was created using our own code using IPython, the rest of the cover with the GIMP image editting software.

Tuesday, 11 March 2014

3D Complex Numbers - Why Not?

The Mandelbrot and Julia fractals are flat 2-dimensional objects, because the are derived from 2-dimensional complex numbers.

It's natural to want to extend the complex numbers to 3-dimensions, to form hypercomplex numbers, to see what kinds of Mandelbrot-like objects might emerge.

How would we do this? Is it possible? Impossible?

The eminent mathematician William Rowan Hamilton tried to do exactly this for quite some time, and failed. The reasons why this fails are not well explained in many guides to mathematics, so we'll have a go here. Myself I struggled to find a convincing but easy to understand explanation until I found the venerable Numbers which has a good explanation at the start of Chapter 7, even if the style is a little old school.
 A key thing to realise about mathematics is that you're free to invent any kind of universe of objects and the rules that govern how they interact. You can play mathematics god. However, if you want others to be interested in your creations they have to be useful, or actually interesting, in some way.

We know the complex numbers are remarkably useful across many fields of real world science, as well as pure mathematics. They're useful because they behave in ways that conform to many norms of familiar number systems. For example, complex numbers are commutative. That means it doesn't matter which order you multiply two complex numbers together. Just like normal numbers 3 x 2 is the same as 2 x 3, for complex numbers (2+3i) x (3+5i) is the same as (3+5i) x (2+3i) = (-9 + 19i). For some invented schemes, or algebras, the assumption of commutativity is not safe.

So we'll proceed in small steps, and remain cautious about which behaviours of normal number systems we want to preserve, or can prove remain true.

Let's start by extending the complex numbers from the 2-dimensional form (a+bi) to 3-dimensional by adding a new "axis" or basis. Let's call it j, but keeping in mind it's not the j used by the engineering community to mean the imaginary i. So we have hypercomplex numbers of the form (a+bi+cj). The parameters a, b and c are simple normal real numbers, not complex numbers. Writing (a+bi) is an easy way of talking about all possible complex numbers because we're committing to any particular a or b.

Let's make a small step forward and see if a very common mathematical operation works as we expect. Remember that with complex numbers addition works by adding the real and imaginary parts of the complex numbers independently. This works because the real and imaginary parts are independent. If they weren't then such simple addition wouldn't work. If you think of complex numbers as being composed of apples and oranges, instead of real and imaginary parts, you can see that you can collect all the apples into a new sum pile, and the same for oranges, but you can't mix the apples with the oranges. It should be straightforward to see that for our hypercomplex numbers, addition works the same, with the real, i and j parts being added independently. The usual behaviours of commutativity (A+B = B+A) and associativity (A+(B+C) = (A+B)+C) work as expected. Importantly, no inconsistencies or incompleteness appears to arise from our addition rules for these hypercomplex numbers.

Addition for our invented hypercomplex numbers isn't problematic. Now let's consider multiplication.

Let's try multiplying a general hypercomplex number by itself, that is, squaring it.

(a + bi + cj)2 = (a2 + abi + acj + abi + b2ii + bcij + acj + bcji + c2jj)
= (a2 - b2 - c2) + (2ab)i + (2ac)j + bcij + bcji

We assumed j2 = -1 just as i2 = -1. Why? Because we want the j basis to behave as the i basis and not have an unnerving asymmetry. We collected similar terms but we were cautious about the ij and ji terms, taking care not to equate them because we don't yet know if they are commutative. That is, we don't equate ij with ji to collect the last two terms.

Great! It seems we now need to find a reasoned way to see if ij and ji can be decomposed or simplified into a combination of basis terms, real, i and j. Why? Because we want multiplication of these hypercomplex numbers to result in new hypercomplex numbers that stay within the same space and not break out, needing new dimensions to describe them.

How can we do this? Well let's apply another constraint derived from another desirable quality. That quality is this - that hypercomplex numbers, when multiplied, results in a new one whose Euclidean magnitude is the same as the Euclidean magnitudes of the factors multiplied. That is, |AB| = |A||B| as the illustrated by the following diagram. Note: this isn't vector multiplication, its multuplying complex or hypercomplex numbers.

We didn't have to ask for this but we want to because it is a normal behavior we do want to see in our invented hypercomplex numbers. So lets apply this to a hypercomplex number multiplied by itself:

| (a + bi + cj)| = | (a + bi + cj) | | (a + bi + cj) | = a2 + b2 + c2

That last expression is simple because the Euclidean magnitude is the square root of each component squared and summed, and the square roots cancel out. But we have that other longer expression for the hypercomplex number multiplied by itself, so we can apply the sum of each component squared to that expression, where each independent components is the scale of the real, i and j parts. also, we don't like square roots so square everything to get rid of them to the algebra clearer:

(a2 + b2 + c2)2 = (a2 - b2 - c2)2 + (2ab)2 + (2ac)2 + ... and the bits with ij and ji.

For the above expression to work, the ji and ij bits need to cancel out to zero. This means ji = -ij. That is, we don't have commutativity, ij does not equal ji.

That's not a bad result! We've shown that by insisting on a natural feature, we must lose commutativity.

Hang on! What if we set ij = 0 and ji = 0 that would seem to work. Hamilton did consider this. But it seems a little too harsh to get rid of terms like that - we don't really have a good reason to make them zero. In fact you could argue that neither ij nor ji can be zero because the magnitudes |ij| must be |i|x|j| which is 1x1 = 1, not zero!

Instead, let's say ij = -ji = k. Now, k can't be a normal number otherwise it would be absorbed into the real part we already have. It must be equivalent but different to the existing bases ... k is a new basis, alongside i and j.

This is what led Hamilton to conclude that you needed a 4th basis for a well behaved algebra of hypercomplex numbers. Three doesn't work, as we have shown. He called these 4-dimensional hypercomplex numbers, quaternions, and they have proved immensely well behaved and useful.

Wow - what a long stretch. But it's the best and most accessible explanation I've found for why naive extensions of complex numbers to 3 dimensions don't work, but 4-dimensional quaternions do.

Monday, 10 March 2014

Delicate Image

We looked earlier at filters applied to the array of values holding the colour information for the Mandelbrot or Julia fractals.

Instead of smoothing the image, we instead use a filter which highlights edges, called a Sobel filter.

I love this image that that results from applying the Sobel filter to a Julia set. I love how it is delicate, detailed and yet has it's own inherent coherent structure. Click on it to show a fuller image.

Amazing that this essentially comes from a very simple iterated function z2+c.  And it's generated by the simple code we develop in the book.

I love it so much it's going to be the cover of the book!

Friday, 7 March 2014

Mathigon Fractals

This is a beautifully presented site about mathematics and it's section on fractals is really very accessible.

Great work and it all aids wider understanding and appreciation of the beauty of mathematics.

Smoother Landscapes

The previous post described using the colour information in a Mandelbrot or Julia image to represent height and so create a surface.

I found some of the plots to be a little spiky or noisy. Applying smoothing takes some of the edges off the height values and makes for a smoother more pleasing landscape. In IPython it is really easy to apply Gaussian smoothing for example. See the following before and after.

Before smoothing:
2-dimensional plot:
3-dimensional plot:

After smoothing:
2-dimensional plot:
3-dimensional plot:

Mandelbrot Mountains

I've previously posted that I'm trying to find an easy way to explain why a naive extension of 2-dimensional complex numbers to 3-dimensional ones isn't possible, and that the answer needs to be 4-dimensional quaternions.

Anyway the underlying aim was to have some kind of 3-dimensional version of the flat Mandelbrot and Julia sets. I'm still working on the quaternion issue but in the meantime, I've written up an easier approach to making 3-dimensional images which produces pleasing results.

The idea is simple - use the colour information in the calculated arrays to represent height or altitude. In this way we have all we need to define a surface or landscape. Remember that the normal calculations determine a value which is the number of iterations reached for each point in the area of interest. This value could be one of two things; (i) the number of iterations reached before the orbit escapes a threshold indicating divergence, or (ii) the maximum iterations we'll allow before we get bored and say the point is unlikely to diverge. For the normal plots this value determines the colour we use to plot the point. This results in a flat coloured area for inside the Mandelbrot set, and a graduation of colours outside. Now we use this value for the height at each point.

Doing this in IPython is very easy. Simply import the mayavi extensions and use a very simple plotting instruction. You can't currently use the pure web remote IPython services as these 3-dimensional surface plots need to use real 3-d hardware, so local installs of IPython are needed (opengl is used).

Here are some examples.