handmade.network » Wiki » Calculus

Calculus is the study of how the output of a function changes as its input changes.

Gentle Introduction

Take the function f(x) = x + 2. Plotting y = f(x) looks something like this:

|   /
|  /
| /
|/
/
|
------------

Every time you go along the x-axis by 1 unit, you also go up the y-axis by 1 unit. In other words, when the input of f(x) is increased by 1, its output is also increased by 1.

If the function was instead f(x) = 0.5x, we'd get this.

|
|         -/
|       -/
|     -/
|   -/
| -/
-/----------

As the gradient of the line is 0.5, every time you go along the x-axis by 1 unit, you go up the y-axis by 0.5 of a unit. In other words, when the input of f(x) is increased by 1, its output is increased by 0.5.

(Note that this will hold true regardless of the y-intercept, so we can translate the graph up and down to our heart's content)

We can therefore mathematically describe the gradient of a linear function as the change of the function's output divided by the change of the function's input.

So,

                   f(x + h) - f(x)
gradient of f(x) = ---------------,
                    (x + h) -  (x)

where h is "the change".

For example, if f(x) = 3x - 2:

f(x + h) - f(x)   (3(x + h) - 2) - (3x - 2)   3x + 3h - 2 - 3x + 2   3h
--------------- = ------------------------- = -------------------- = -- = 3.
       h                      h                        h              h

I.e. the gradient of f(x) = 3. We'll write this as f'(x) = 3, although there are alternate notations.

Practise questions: [make sure use the formula - you'll see why in a bit!]

  • 1. What is the gradient of f(x) = 4x + 2?
  • 2. In the above formula, why can't h = 0?
  • 3. Find g'(x) where g(x) = -3x + 7.
  • 4. (a) If h'(x) = 10, what possible functions could h(x) be?
  • (b) What do you think h''(x) is? What about h'''(x)?
  1. f'(x) = 4

  2. Because you can't divide by 0.

  3. g'(x) = -3

  4. (a) h(x) = 10x + c

(b) h''(x) = h'''(x) = 0

As discussed in question 2, h cannot be 0. However, we can consider what will happen as h approaches 0: the same thing for any other value for h - we'll still be able to calculate our gradient.

This is useful, because it allows us to find the gradient of more complex functions.

Consider f(x) = x ^ 2.

|       |
|       |
|      /
|     /
|   -/
| -/
-/----------

As you can see, it gets steeper as x increases. This means that the gradient is not constant! The gradient changes as x changes.

We can't just see what happens to the output of the function when we increase the input by 1, because it'll depend on: a) Where we start b) And the size of our 'change'

So how can we work out what the gradient is, at, let's say, x = 1? The simplest thing to do is to draw a line tangent to the curve at this x = 1, and then find the gradient of that line, but that's not very mathmetical, is it?

If only there was a way to algebraically consider for any starting value of x, what would happen to the output of the function if x was 'nudged' by an infinitely small amount...

Oh wait, there is.

        lim  f(x + h) - f(x)
f'(x) = h->0 ---------------
              (x + h) -  (x)

        lim  ((x + h) ^ 2) - (x ^ 2)
      = h->0 -----------------------
                        h

        lim  (x ^ 2 + 2xh + h ^ 2) - (x ^ 2)
      = h->0 -------------------------------
                            h

        lim  2xh + h ^ 2    lim  h(2x + h)   lim  
      = h->0 -----------  = h->0 --------- = h->0 2x+h
                  h                  h

      = 2x                

This means at any point on the x^2 graph, the tangent line at the point will have a gradient of 2x.

This means that the gradient of f(x), f'(x) = 2x.

And that the gradient when x = 1 is f'(1) = 2. (In other words, the tangent drawn at x = 1 would be of the form y = 2x + c).

Now, let's take a step back. The process of going from f(x) to f'(x) is called differentiating, or finding the derivative [of f(x)].

You'll often also see the following notation to indicate the derivative:

y = x^2

dy
-- = 2x
dx

The d- prefix means "a small change of", so it's easy to work out what this means.

It's also worth noting that this would also imply that:

dy = 2x dx

You'll understand why this is useful if you study implicit differentiation.

Going from f'(x) to f(x) is called integrating, or finding the antiderivative. It's also notated like this:

 /-
 |
 |  2x dx = x^2
 |
-/

Well, almost. Remember question 4 (a)? There are a range of functions that all have the same derivative, i.e. any translation on the y-axis. This means we actually have to write:

 /-
 |
 |  2x dx = x^2 + c
 |
-/

Forgetting the "+ c" is quite the common mistake, but if you do forget it, you'll end up in quite a mess with more advanced integration concepts. "c" is called the constant of integration.

By the way, integrating is usually more difficult than finding the derivative of a function. In fact, there are bunch of that just don't have an antiderivative.

Trying to do this formula

        lim  f(x + h) - f(x)
f'(x) = h->0 ---------------
              (x + h) -  (x)

in reverse just isn't very easy. Instead, there are a bunch of tricks and methods to use to find the anti-derivative of a function. Knowing which one to apply isn't always obvious, and'll take a lot of practise.

One last thing. It's important to understand what a "function of <something>" means. In calculus this phrase is used to denote any expression that depends on the value of a given variable. It doesn't have to be explicitly written as a function.

For example, if you were told y = 2x^2 + 4x + 6, there are several things that could be called "functions of x":

  • y
  • x^2
  • 2x^2
  • 4x
  • 2x^2 + 4x

However, things like the "6" and the factor of 2 would both be considered "constants".

Practise questions:

  • 1. f(x) = x^3. What is f'(5)?
  • 2. g'(x) = 3x^2. What is g(x)?
  • 3. y = 10x. What is dx/dy?
  1. 75

  2. x^3 + c

  3. 1/10

Finding the Derivative

Notation: f(x), g(x), h(x) etc. are functions of x, and a, b, c, etc. are constants.

a

y = a

dy
-- = 0
dx

f(x)

y = f(x)

dy
-- = f'(x)
dx

f(x) + a

y = f(x) + a

dy
-- = f'(x)
dx

f(x) + g(x)

y = f(x) + g(x)

dy
-- = f'(x) + g'(x)
dx

f(x) * a

y = f(x) * a

dy
-- = f'(x) * a
dx

f(x) * g(x)

y = f(x) * g(x)

dy
-- = f(x)*g'(x) + g(x)*f'(x)
dx

f(a * x)

y = f(a * x)

dy
-- = f'(x) * a
dx

f(g(x))

y = f(g(x))

dy
-- = f'(g(x)) * g'(x)
dx

sin(x)

y = sin(x)

dy
-- = cos(x)
dx

cos(x)

y = cos(x)

dy
-- = -1 * sin(x)
dx

x^a

y = x^a where a != 0

dy
-- = a * x^(a-1)
dx

ln(x)

y = ln(x)

dy   1
-- = -
dx   x

a^x

y = a^x

dy
-- = ln(a) * a^x
dx

e^x

y = e^x

dy
-- = e^x
dx