The Five Minute Guide to Calculus

Certain aspects of generating fractals (distance estimation, finding critical points of a function, Newton's method) requires that we are able to calculate the differential of a function. If your mathematical education stopped at the age of 16, you probably won't have learned calculus at all and the very word "calculus", if it means anything at all to you, means "some kind of advanced maths that I could never grasp in a million years". Poppycock! You can learn calculus if you have the mathematical education of a twelve year old. If you're American, replace "maths" with "math". It's the same thing.

Why Learn Calculus?

Getting anywhere in carpentry is impossible until you understand the concept of "wood grain". Your progress as a musician stops until you learn to read music. Similarly, your progress in any scientific study is limited until you learn calculus. Don't believe me? What differentiates psychology from shamanism is statistics, the ability to distinguish between significant results and chance results and that requires calculus. In actual fact, you probably have learned calculus. You may dimly remember from some long-ago science lesson Newton's equations of motion, linking displacement, s, initial velocity, u, acceleration, a, final velocity, v and time, t:

v = u + at
s = ut + ½at2
v2 = u2 + 2as

You then learned these by rote, applied them in an end-of-year test and promptly forgot about them. What your physics teacher almost certainly failed to mention was that all these equations could be derived from scratch if only you knew that velocity was the rate of change of displacement with respect to time and that acceleration was the rate of change of velocity with respect to time. It's no coincidence that the discoverer of these equations of motion and the inventor of calculus were the same person: Isaac Newton (pace, Leibniz fans: I know he also invented calculus). Without the mathematical tool, he couldn't have made the world-changing discoveries.

So How Do I Do It?

Differential Calculus

We'll see how to differentiate a simple function from first principles. This is the bit where you'll need the maths education of a twelve year old. Let's take a simple function:

y = x2

If we add a little bit to x, written as ∆x, y will also change by a little bit, ∆y. But the small change in y won't be the same as the small change in x because yx. We write down the equation as:

y + ∆y = (x + ∆x)2

Expanding the brackets (twelve year old maths) gives us:

y + ∆y = x2 + 2x∆x + ∆x2

Subtracting y from both sides gives us the size of the change in y:

∆y = 2x∆x + ∆x2

Dividing both sides by ∆x gives us the little change in y with respect to a little change in x:

∆y / ∆x = 2x + ∆x

Note that the first term in the right-hand side does not depend on ∆x. Now here comes the magic bit. If we let ∆x shrink to nothing at all, the left-hand side doesn't become infinity because ∆y is also shrinking to nothing. What does happen is that the annoying ∆x on the right-hand side disappears. What we are left with is the instantaneous rate of change of y with respect to x. For this, we replace with d and obtain the differential of y = x2:

dy/dx = 2x

Visually, we can picture this as taking a ray at right angles to the graph of a function at a point and then drawing a straight line at right angles to the ray. This line is called the tangent and its slope is the same as the value of the differential at the point. With larger deltas, the tangent is only an approximation of the slope.

Without too much difficulty, we can differentiate y = x3:

y       = x3
y + ∆y  = (x + ∆x)3
        = x3 + 3x2∆x + 3x∆x2 + ∆x3
  ∴ ∆y  = 3x2∆x + 3x∆x2 + ∆x3
∆y / ∆x = 3x2 + 3x∆x + ∆x2 

Letting ∆y and ∆x shrink to nothing so that only the first term in the right-hand side remains leaves us with:

dy/dx = 3x2

Without forcing ourselves through the tedium of differentiating the fourth power we can already see the pattern that gives the general rule for differentiating a function of the form xn:

dxn
--- = nxn-1
dx

Second differential

Remember that velocity is the differential of displacement with respect to time and that acceleration is the differential of velocity? This means that acceleration is the differential of the differential of displacement with respect to time, or the second differential for short. To do this, we just apply the same differential rules to the differential function. We also use a slightly different notation. This means that we have the general formula for the second differential of functions of the form xn:

d2xn
---- = n(n-1)xn-2
dx2

Should we need to, we can do this repeatedly to get the third differential, fourth differential, etc.

Other Functions

In principle, we can differentiate any differentiable function from first principles, but this is sufficiently tedious that it makes sense to take advantage of the hard work of others and simply to look up the differential in a table. These days, of course, we can also use a tool like Mathematica to spit out the function we're looking for.

Prime Notation

This is a shorthand notation for first, second, etc. differentials that is a lot more convenient to use than the notation I've been using so far. It simply uses the 'ʹ' (prime) character:

f(x), fʹ(x), fʹʹ(x), fʹʹʹ(x), f(4)(x), etc.

Integral Calculus

This is just differentiation in reverse. When we integrate a function we end up with the function that, if differentiated, would give us the function we started with. From the general form above, we can derive the general formula for integrating functions of the form xn:

∫xndx = xn+1 / (n+1)
This rule doesn't work when n = -1. No xn function will produce 1/x as its differential because the differential of x0 (i.e. 1) is 0. The integral of 1/x is loge(x).

The '∫' thing is just an old printing character for 's'. We visualize the operation as summing all the infinitely thin lines under the graph of the function which is where the notation comes from. We can see that this is the case if we consider the function y = x. The graph of the function is a half a square of sides x which gives us the area under the graph as ½x2. You should also be able to figure out where Newton's equations of motion come from - they are the results of integrating velocity and/or acceleration.

A one-way function is something that is easy to do one way but (close to) impossible to do the other. For example, you can multiply two prime numbers very easily, even if they're large, but finding which two prime numbers were multiplied together to produce a given number (prime factorization) is astonishingly hard. Differentiation is the same: we can do it easily enough but doing it backwards to integrate is often astonishingly difficult. Therefore, we'll generally use tables of integrals (or even numeric methods) to integrate a function.

Combining Functions

When f(x) is a combination of two other functions, p(x) and q(x), there are rules to how we obtain the differential of the combined function. If you're interested and not too easily bored, you can derive these from first principles but deriving the quotient rule, in particular, is tedious in the extreme. So I'll just give you the rules.

In the examples that follow, we'll be using the differentials of sin(x) and x2 which are cos(x) and 2x respectively.

Sum / Difference of Two Functions

(p(x) + q(x))ʹ = pʹ(x) + qʹ(x)
(sin(x) + x2)ʹ = cos(x) + 2x

Product of Two Functions (Product Rule)

(p(x)q(x))ʹ = pʹ(x)q(x) + p(x)qʹ(x)
(x2·sin(x))ʹ = 2x·sin(x) + x2·cos(x)

Ratio of Two Functions (Quotient Rule)

(p(x) / q(x))ʹ = (pʹ(x)q(x) - p(x)qʹ(x)) / q(x)2
(sin(x) / x2)ʹ = (cos(x)·x2 - 2x·sin(x)) / x4

Function of a Function (Chain Rule)

p(q(x))ʹ = pʹ(q(x))·q'(x)
(sin(x2))ʹ = 2x·cos(x2)

The chain rule is important for our purposes, since we apply it to calculate the cumulative differential of f(z) for boundary tracing.

There you go: that's all the calculus required to generate fractals.

Back to the index