 Right, let's do the Mandelbrot set in Excel. Now, why would you want to do this? I don't know. You probably shouldn't. I just do it because I'm an idiot, belligerent, and mostly motivated by spite. So yeah, you can do it in this. You probably shouldn't. Maybe it's helpful in some ways. So what is the Mandelbrot set? So it's a fractal. It's the prototypical fractal number file of COVID. I'm sure YouTube has got more than enough videos of people zooming in on it. I'm not going to cover the maths in too much detail. But the basic idea is this equation here, deceptively simple, but it produces this amazingly complicated pattern, which is probably why it's been an enduring kind of image, hasn't it? All of this complexity from something so simple. So the idea is that you take a number. Usually you start at 0, then you square it, and you add a particular constant to it to get the next number in the sequence. And then you square that number and add the same constant. Then you square it again, add the same constant, square it again, add the same constant. Now in real numbers, number line one, two, three, four, and so on, that's actually kind of boring. Nothing very interesting happens. But in the complex plane where you've got real numbers in that direction, your lateral slash imaginary numbers in that direction, things get a bit more interesting because complex numbers, when you multiply them or square them, they start to kind of circle around. So this, as you go through and iterate this, it might go here, here, here, here, jump around, jump around, jump around. And kind of one of two things happen. Either it escapes off and blows up to infinity, or it kind of centralizes on an individual number. Now in the Mandelbrot set, it's colored black if we think it's going to converge. And then, if not, we kind of color code it based on how fast is it going to escape and so on. So we can't really say for sure that it'll definitely converge, but we can iterate through dozens, hundreds, even thousands of times and find that it kind of is converging and we color it black. That's kind of it. That's as far as into the maths I'm going to go into. Now I'm going to start with kind of a blank sheet here. I've already set this up to be the right scale. It's just two sequences going up and down. I've made it a square grid. And I'm going to set myself up a complex plane. So I'm going to use the function called complex. Yep, Excel does manage complex numbers. It uses imaginary numbers. They're awkward, but it does it. So complex, let's do, that's the real number and that as the imaginary number. Now, you might be thinking, ah, you put these in with sequences. Let's put a hash on the end. Oh, if it was this simple, but it isn't. These functions do not play nicely with the dynamic array. So we've got to go do it old school, dragging and dropping. So here we go, minus 1.5, minus 1.5 times the imaginary unit i. So here we go. We could fill that like so. Except actually, I'm going to get rid of that. What are all the bars? I'll keep dragging it around. So let's just get rid of it. So we could fill this. We've got to drag it across and so on. Except, oh, yes, because we're now dragging it across. So we've got to lock off certain axes. So I've got to lock off number one and I've got to lock off A. So this actually does it quite quick if it doesn't have to then redo everything with an error. So there we go. So that's kind of our complex plane. So we do complex and that. Now the handle brought set requires two functions. One thing, we've got to square this and then add a new thing. And we can't just go that plus this error. We've got to kind of use the imaginary functions to do this other complex number functions. So if we wanted to say, let's say complex one, two, complex two, one. All right, two complex numbers. I can't just add these. It doesn't work. I'm going to use imaginary sum. So I can add that, add that, it'll sum them together, no problem. Basically, I think this must be a hack on top of it because this is basically being treated as a text string rather than like a 2D-origin number or something like that. And if I want to multiply them, well, I need to do imaginary product. There we go. You can see it has a bit of a spin around. And if I want to raise them to a power, I need to use im, power. So I can put, raise that to the power two. There we go. I'm not going to dig too much into this. But what we can do is if we start with this, well, we want to do imaginary power to, and around that, I want imaginary sum, I am sum, sorry, of that complex function and, well, the same thing again. So I'm going to just copy and paste that to see if we have some effort. So there we go. There was like the first iteration of the Mandelbot set. Where do these things lie? Now, this is just an imaginary grid. They're just numbers for now. What we need to know is how far away are they from the center? What's the absolute magnitude? So for that we need im, absolute, imaginary, absolute. This will always be a single number. And what you can kind of see is kind of zero towards the middle. It gets bigger. So what we can do now is kind of start iterating this so we can copy and paste where it says imaginary sum all the way to the end, everything inside that. We can copy that. And here is the complex number here. That's the thing we start with. So I'm going to paste that into there and we get our second iteration. We can see these ones outside are really firing off up to a high number. But actually, we're still zero. We're kind of zero one-ish here. Maybe you'll be able to see kind of a shape forming if we do this. I'm going to find that again, just that z number there. Paste it in. In fact, let's just do a couple wherever it says this complex inside the imaginary power function. We'll just paste the same thing in. So this is kind of nesting multiple functions. And we can drag it across. And now these numbers are getting so big that they can't be displayed. But we're starting to see kind of a pattern. Let's change this slightly, maybe to minus 1.7. We'll shift it across, maybe minus 2. There we go. So we can kind of see that pattern appearing. Now pasting that in is going to be an absolute nightmare to do again and again and again. So what we are going to do is use a recursive lambda to do this. I've done a few times now. I'm getting reasonably good at knowing how to use these now. That's quite neat things. So for one thing, I'm going to put in this corner 20 because this is just going to be what my limit is. I want to put it somewhere kind of convenient-ish. So let's start with kind of what is the lambda going to be? So the parameters I need for this are going to be z and c and then i and then I'm going to pipe a limit to it. We could deal with that elsewhere. I'm just going to put them in here. So we need z. That's going to be our input that we iterate on c. That's the constant. So each one of these locations is that constant. And then we need a limit. Right. So the first thing we need to do is how are we going to escape the function? When do we want it to stop? Otherwise it'll just continue being called forever. So we start with if and there's actually there's two conditions that I want this to stop on. So I'm going to add in or is a logical kind of test here. So if one of these two functions is true, it's going to stop. So if i is equal to the limit or if the imaginary absolute value of z our input value is greater than two. So there's kind of a mathematical proof about this. If it's greater than two, it's not coming back. It's not going to converge. So we can stop it. So we will end it there. So one of those conditions are met. I want to return i. That's going to be a number and is going to be how many iterations we've done. If that is all false, we're ready to call it again. Well, we'll call the function and I'm going to call it Mandelbrot. And let's have a look at what things we need. So we need to do C, i, deal with z last. C, we're going to remain exactly the same. We're not going to change that. I, we're going to add one to it because we're going to increment the loop and then the limit will pipe the limit back to it. Close off a couple of brackets there so it's all done. Now the Mandelbrot function, what is this? Well, we're going to use what we had earlier. Imagine we sum of I am power of the input z squared and that's going to be summed with C. And that should just be it. Hopefully this will just return a calculation error. Control C that. Then in my name manager, I'm going to put this in and I name it Mandelbrot which is what I added. Paste that in there. Okay that. So now if I type Mandelbrot, well my z, my input, well actually I'm going to start with zero. I'm not going to initiate with anything else. But the constant is going to be a complex number and the real component is going to be that. I'm going to remember to lock off row one and the imaginary corner is going to be that. I'm going to remember to lock off column A. I don't need anything other than that. I am going to initiate with just one. I can do it with zero if it doesn't really matter. And the limit I'm going to feed it in is just that. Let's make sure I lock that off. So that should now just return. How many iterations does it take to escape to get that absolute value above two? You can see already in the top corner it just took one. Took two for there. And now we can see we've got these 20s in the middle. That is because it's hitting the limit. It hasn't kind of escaped out yet. So it's being highlighted as 20. So now let's get some conditional formatting in. And conditional formatting highlights cells rule. If it's equal to, well if it's equal to the limit, well I'm going to do it the traditional way. The Mandelbrot's done. Just fill it in with black. So you can start to see that's kind of the shape we're after. And conditional formatting. I'm going to do another one of color scales. If I manage the rules, I can move the priority around so that the black one will, whenever we hit the limit, it will always be black. And if not, we get that color scale. So this is, I think they call escape velocity technically. That's the number. And again, all we need to do is change our number format. Three semi-colons there. And there we are. We're now seeing it appear. And what I can do is I can just ramp this number up to however high I want. 50, you can get a little bit. Higher resolution, 100. Probably don't need that high unless we really expand the size of this. So what I could do is kind of add more to this. I could double the size of this. I can double the size of this as well. Let's just see, 50 to scale it in a particular way. And now I can begin to drag all this to make it squarish again. Unfortunately, it doesn't work with the dynamic ways, but you can see it's not going to fill in everything for me. We're starting to see that plot appear, because it is not magic, it is just some mathematics. You can do this on a calculator if you really wanted. And now if we ramp that up to maybe 200 iterations, we start to get to see that Mandelbrot set shape. So if you ramp it up to much higher values, how many cells is this? I think it's like 256 cells vertically in like one and a half of that wide. You can start to get some pretty good resolution for it. Obviously, if you want to do this properly, use proper software, something that can turn through the imaginary numbers really fast and efficiently and do it on a pixel basis. Don't do this for anything other than just testing and playing around, please. This is not 100% serious work. This is just messing around, obviously. But you can do it. That's the thing. You can do it. The ledgerance and spite will get you really quite far with this.