TExcelTAD
Home › Calculus Essentials › Calculus Intro

Calculus Intro

Calculus is the mathematics of change. It answers two questions: how fast is something changing right now, and how much has built up over time? This course teaches both, with every idea checked in Python.

Two big ideas

Almost all of calculus grows from two questions that turn out to be opposites of each other:

Idea Question it answers Everyday example Main tool
Rate of change How fast is this quantity changing at this instant? The speedometer reading of a car the derivative
Accumulation How much has built up over an interval? The distance on the trip counter the integral

If you know the speed at every moment, you can work out the total distance (accumulation). If you know the distance at every moment, you can work out the speed (rate of change). The Fundamental Theorem of Calculus says that these two operations undo each other. You will prove that to yourself with code in the definite integral lesson.

A first taste: speed from position

A ball dropped from a tower has fallen s(t)=4.9t2s(t) = 4.9t^2 metres after tt seconds. What is its speed at exactly t=2t = 2? Speed is distance divided by time, but "at exactly one instant" means zero time and zero distance. Calculus gets around this by shrinking the time interval and watching where the average speed is heading:

python · try it yourself
def s(t):
    return 4.9 * t**2          # metres fallen after t seconds

t = 2.0
for h in [1, 0.1, 0.01, 0.001, 0.0001]:
    avg_speed = (s(t + h) - s(t)) / h
    print(f"interval {h:<7} average speed = {avg_speed:.5f} m/s")
interval 1       average speed = 24.50000 m/s
interval 0.1     average speed = 20.09000 m/s
interval 0.01    average speed = 19.64900 m/s
interval 0.001   average speed = 19.60490 m/s
interval 0.0001  average speed = 19.60049 m/s

The averages close in on 19.6 m/s. That limiting value is the derivative of ss at t=2t = 2. The rule you will learn later, s′(t)=9.8ts'(t) = 9.8t, gives 9.8×2=19.69.8 \times 2 = 19.6 straight away.

A first taste: distance from speed

Now go the other way. A car's speed is v(t)=3tv(t) = 3t m/s. How far does it travel in the first 10 seconds? Chop the time into small steps, assume the speed is constant during each step, and add up speed×time\text{speed} \times \text{time} for all of them:

python · try it yourself
def v(t):
    return 3 * t               # metres per second

for steps in [10, 100, 1000, 10000]:
    dt = 10 / steps
    distance = sum(v(i * dt) * dt for i in range(steps))
    print(f"{steps:>6} steps: distance ≈ {distance:.3f} m")
    10 steps: distance ≈ 135.000 m
   100 steps: distance ≈ 148.500 m
  1000 steps: distance ≈ 149.850 m
 10000 steps: distance ≈ 149.985 m

The sums approach 150 m, the integral of 3t3t from 0 to 10. More steps give a better answer, and the exact value is the limit as the step size goes to zero. This "chop, multiply, add" idea is called a Riemann sum.

Why programmers need calculus

You can write a lot of software without calculus, but it sits under many fields that programmers work in:

Where What calculus does there
Game physics Position is the integral of velocity, velocity the integral of acceleration. Every physics step in a game loop is a tiny numerical integration (Game Physics).
Animation and UI Easing curves such as ease-in-out are functions whose slope controls how smooth a motion feels.
Machine learning Training means moving the model's weights against the gradient, a vector of derivatives, of the error (Machine Learning).
Neural networks and LLMs Backpropagation is the chain rule applied through millions of layers and weights (Generative AI & LLMs).
Graphics Bézier curves, surface normals and lighting integrals.
Finance and science Continuous interest, growth and decay models, and differential equations.
Algorithms Newton's method for roots, numerical integration and optimisation.

Note: You will rarely differentiate by hand at work. Libraries do that for you. What you need is to understand what a derivative or integral means, so you can tell when the computer's answer makes sense.

How this course is organised

The course follows the chapter order of Debra Anne Ross's Master Math: Calculus, used here only as a guide to topic order. All explanations, examples and exercises are original.

  1. Functions: domain and range, function types, composition and inverses, transformations, exponentials and logs, trig and hyperbolic functions, polynomials, complex numbers and conic sections.
  2. The Derivative: limits, continuity, the differentiation rules, maxima and minima, optimisation, related rates, L'Hôpital's rule and Newton's method.
  3. The Integral: antiderivatives, Riemann sums, the Fundamental Theorem, area, volume, substitution, integration by parts and numerical integration.
  4. Series and Approximations: sequences, convergence and Taylor series, which is how computers evaluate sin and exp.
  5. Vectors, Matrices, Curves, Surfaces and Motion: the geometry needed for motion in 2D and 3D.
  6. Partial Derivatives: functions of several variables, gradients, Lagrange multipliers, Jacobians and Hessians.
  7. Vector Calculus: multiple integrals, line integrals, divergence and curl, and the big integral theorems.
  8. Introduction to Differential Equations: separable, linear and second-order equations, solved by hand and with Euler and RK4.
  9. Calculus in Computing: gradient descent, backpropagation, automatic differentiation, physics integration in game loops and easing curves.
  10. Practice: exercises, and a mini project that builds a tiny autodiff engine and trains a neuron.

Learning paths

You do not have to read everything in order. Pick the path that fits your goal (some of these courses are still planned; see the roadmap):

Goal Suggested path
School to university Basic Math → Algebra → Pre-Calculus → this course → Calculus in Depth → Linear Algebra
Game developer Basic Math → this course (chapters 1, 2, 5 and 8) → Linear Algebra → Game Math → Game Physics
AI / ML engineer this course → Linear Algebra → Probability → Machine Learning → the Machine Learning track
Deep learning and LLMs this course (chapter 6 and Calculus in Computing) → Linear Algebra → Generative AI & LLMs

Tip: You should be comfortable with algebra (solving equations, working with exponents) and basic Python. If exponents or logarithms feel rusty, review Exponents and Logarithms first.

Exercises

Exercise 1: Rate or accumulation?

For each question, say whether it needs a derivative (rate of change) or an integral (accumulation): (a) how fast a download is progressing right now, in MB/s; (b) the total energy a server used over a day, given its power draw at every moment; (c) how steeply a hiking trail climbs at one point.

Answer

(a) derivative, (b) integral, (c) derivative.

Solution
  • (a) "Right now" and a unit per second mean an instantaneous rate: a derivative of the amount downloaded.
  • (b) Power is energy per second. Adding up power×time\text{power} \times \text{time} over the whole day accumulates energy: an integral.
  • (c) Steepness at one point is the slope of the height profile there: a derivative.

Exercise 2: Average speed by hand

A cyclist's position is s(t)=2t2s(t) = 2t^2 metres. Work out the average speed between t=3t = 3 and t=3.1t = 3.1, then guess the instantaneous speed at t=3t = 3.

Answer

Average speed 12.2 m/s; the instantaneous speed at t=3t = 3 is 12 m/s.

Solution
s(3)=2⋅9=18s(3.1)=2⋅9.61=19.22average=19.22−180.1=1.220.1=12.2 m/s\begin{aligned} s(3) &= 2 \cdot 9 = 18 \\ s(3.1) &= 2 \cdot 9.61 = 19.22 \\ \text{average} &= \frac{19.22 - 18}{0.1} = \frac{1.22}{0.1} = 12.2\ \text{m/s} \end{aligned}

Shrinking the interval (3.01 gives 12.02, 3.001 gives 12.002) points to 12 m/s. The derivative rule s′(t)=4ts'(t) = 4t confirms it: 4×3=124 \times 3 = 12.

Exercise 3: Shrink the interval in code

Change the falling-ball program so that it computes the speed of s(t)=2t2s(t) = 2t^2 at t=3t = 3 with intervals 0.1, 0.01 and 0.001.

Answer

12.2, 12.02 and 12.002 m/s, approaching 12.

Solution
python · try it yourself
def s(t):
    return 2 * t**2

for h in [0.1, 0.01, 0.001]:
    print(h, round((s(3 + h) - s(3)) / h, 6))
0.1 12.2
0.01 12.02
0.001 12.002

The extra term is exactly 2h2h, because 2(3+h)2−18h=12h+2h2h=12+2h\frac{2(3 + h)^2 - 18}{h} = \frac{12h + 2h^2}{h} = 12 + 2h.

Exercise 4: Distance from a constant-plus-growing speed

A sprinter's speed is v(t)=2+tv(t) = 2 + t m/s. Estimate the distance covered in the first 4 seconds with a Riemann sum of 1000 steps, and check it against the area of the trapezoid under the graph.

Answer

About 15.992 m with 1000 left-endpoint steps; the exact distance is 16 m.

Solution

The graph of vv is a straight line from 2 (at t=0t = 0) to 6 (at t=4t = 4). The area under it is a trapezoid: 2+62×4=16\frac{2 + 6}{2} \times 4 = 16.

python · try it yourself
steps = 1000
dt = 4 / steps
distance = sum((2 + i * dt) * dt for i in range(steps))
print(round(distance, 3))
15.992

The left-endpoint sum is slightly too small because the speed is rising during each step. The error is 4×42×1000=0.008\frac{4 \times 4}{2 \times 1000} = 0.008.

Test yourself

Which calculus tool answers "how fast is the temperature rising at 3 pm?"

  1. The integral
  2. The derivative
  3. A conic section
  4. A complex number

In the falling-ball example, why do we shrink the interval hh instead of setting h=0h = 0?

  1. Python cannot multiply by zero
  2. With h=0h = 0 the average speed becomes 0/00/0, which has no value, so we look at the limit instead
  3. Smaller intervals make the ball fall faster
  4. Because h must always be an integer

Training a neural network moves the weights in the direction opposite to what?

  1. The gradient of the loss
  2. The integral of the inputs
  3. The largest weight
  4. The learning rate