Image credit: Ionut Stefan
To paraphrase one of my former college professors, this post should’ve been called “differential equations”, but then none of you would’ve clicked on it. I do hope that I didn’t mention that term too early though and scared you all away. After all, you made the effort of opening this page, so why not read on for 30 more seconds?
I know, scary stuff. But I promise this won’t be one of those super-abstract, incomprehensible tutorials that assumes you already know the stuff that you’re here to learn. We’re going to start from some very basic notions and from truly simple examples. If you’re a physicist or a mathematician or basically anyone who has a formal education in this topic, you might wanna skip towards the end though. Otherwise you might find yourself screaming at the computer: “NO! NO! Absolutely not! It’s not a squiggly math formula, it’s an equation that relates one or more unknown functions and their derivatives! Everybody knows that!” I do get your frustration, but some people need to start from somewhere else to get to where you already are.
What are differential equations
So what’s a differential equation? Well, it’s a squiggly math formula that lets us describe a whole lot of things. Today we care about things changing over time. In the case of our virtual neuron, that would be the evolution of its membrane potential over time. But simulating that requires us to understand some basics, so we’ll start with something simpler. Much simpler.
Let’s say we’re watching a cat that’s moving around. And because we have literally nothing better to do in this imaginary world, we want to describe the distance that the cat is covering over a period of 30 seconds. At the beginning of this silly “experiment”, that is, at time
But as it notices that we’re staring, it presumably gets a bit creeped out, so it starts to slowly inch away from us. That’s great news, because now we can proceed with our observations: we see that after one second (
In formal math, we would write that
While we wrapped our heads around that, the cat got even more weirded out and now it’s actively trying to outrun us, so it’s actually picking up speed the longer we look at it. Since, like I mentioned, we’re really bored, this is even more interesting, so we begin a new observation period. This time, the cat starts again at 0, but after 1 second, it’s 1 centimeter away, after 2 seconds – 4 centimeters, after 3 seconds – 9 centimeters, and so on, until, at the end of our standard 30 seconds, it’s a full 900 centimeters away!
Again, in math, the pattern we observed above could be written as
The equation of an oscillating cat
Coming back to the cat, the poor thing seems to have realized there’s no escape from this imaginary hell, so now it’s just pacing up and down the room, in a sort of oscillating pattern.
In this case, we’re no longer looking at the distance covered within a given timeframe, but at the position of the cat in the room (which we’re still calling
At this point, I assume that you might be asking yourself some of the same questions I did when I first started learning these things, such as:
- Where in the freaking fresh hell did this entire thing come from? Am I supposed to just…look at squiggly lines and spit out such formulas?
? ? Who the heck are these? And how do you even pronounce this guy: ? (It’s “nu”, sounding kind of like “new”)- hyperventilates in math
- I want to know who
is, but in order to do that, I need to know who is? BUT WHO IS ?? - I just want to get my computer to show me this graph, how am I supposed to go from elvish to code?
I get it. Honestly, just breathe. If you wanna shed a few tears or snap a pen, that’s also ok. After that, bear with me. We will answer all of these one by one, so we will need to dwell in uncertainty for a bit longer. Let’s start with the easiest part: where did the equation come from? Well… from the internet. And no, you don’t need to come up with them yourself (at least not yet). As you learn more about the topic, you will see that there are established models for neurons, brain areas, even the whole brain. Of course, if you wanna be hardcore, you might eventually come up with your own model or at least tweak an existing one. But we’ll get to that later.
Alright, but who are the Greek letters? And for some reason A? I know you’re going to dislike this, but they are pretty much whomever we want them to be. “But how do we choose???”, you’re probably wondering, crushed under the weight of responsibility. Well, I already picked out some values that look nice, but truth be told, if that weren’t the case, you’d have absolutely no idea what would be good values. So you’d just have to try out a bunch of them, until you found something appropriate. In fact, I encourage you to do so anyway. It’s at this point that I’ll share a secret with you: all the Python code for generating the figures in this article can be found here. And it’s written in a beginner-friendly way, so hopefully everyone can follow along.
It’s important to note here that in your journey towards building virtual neurons, brains, or what-have-you, you will often come across such parameters. In some cases, you will know what values to assign to them based on experimental measures or on other people’s work or on intuition. More commonly, you will have to resort to good ol’ guessing (there are ways to do so automatically and systematically, without having to change each value manually, look at a plot, try another one etc, but that’s a story for another time).
Practical solution to the cat equation
Alright, the spiciest problem remains: how do begin to solve this beast? How do we go from the mathy stuff to the pretty stuff? I have to mention here that some differential equations have what’s called analytical solutions – that means that you grab a pen and a piece of paper and you (somehow) solve the equation, basically as if you were solving
First of all, let’s be clear on what our objective is: we want to find the values of
But coming back to our numerical solution. We now have a value for
Now, let’s take a step back. We said in the very beginning that
With this is hand, we just need to pick a
End of part 1 & small exercise
If you’ve made it through the entire section above, congratulations! Now it’s time for a well-deserved snack and a break. Let these memories consolidate until next time, when we’ll finally tackle that virtual neuron. And to get in shape for the big fight, you can try to implement a numerical solution to the equation below in the programming language of your choice. Feel free to share the plots with the world, either in the comments or on your favorite internet platform.
Update: part 2 is now up.
What did you think about this post? Let us know in the comments below. And if you’d like to support our work, feel free to share it with your friends, buy us a coffee here, or even both.
Subscribe to our RSS feed here.
You might also like:

