Calculus and Multivariable Calculus: From Motion to Fields

A complete, interactive guide from limits and derivatives to gradients, multiple integrals, and vector calculus.

Save & go offline: Press Ctrl+S / Cmd+S to download this single HTML file. All interactive canvases work offline. Math rendering uses MathJax CDN.

1. Introduction — Limits as Foundation

Calculus is the mathematics of change. Both differentiation and integration are built on one idea: the limit.

We say \(\displaystyle \lim_{x\to a} f(x) = L\) if we can make \(f(x)\) as close to \(L\) as we want by taking \(x\) sufficiently close (but not equal) to \(a\).

Intuition Limits let us talk about "instantaneous" behavior: instantaneous velocity, instantaneous slope, area under infinitely thin slices. Without limits we'd be stuck with averages.

The derivative is a limit of average rates. The integral is a limit of finite sums. Master limits, and the rest follows.

2. Single-Variable Differential Calculus

The derivative measures instantaneous rate of change:

$$ f'(a) = \lim_{h\to 0} \frac{f(a+h)-f(a)}{h} $$

Geometrically, it's the slope of the tangent line — the limit of secant lines.

h = 1.00 secant slope =

Purple = secant, Pink = true tangent at \(x=1\) for \(f(x)=x^2\). As \(h\to0\), slopes converge to \(f'(1)=2\).

Core Rules

RuleFormExample
Power\((x^n)' = n x^{n-1}\)\((x^3)'=3x^2\)
Constant multiple\((cf)'=c f'\)
Sum\((f+g)'=f'+g'\)
Product\((fg)'=f'g+fg'\)
Quotient\((f/g)'=(f'g-fg')/g^2\)
Chain\((f(g(x)))' = f'(g(x))g'(x)\)\(\sin(x^2)' = 2x\cos(x^2)\)

Applications

Optimization: critical points where \(f'(x)=0\). Check \(f''\) for max/min.

Related rates: differentiate both sides with respect to time \(t\). E.g., \(V=\frac43\pi r^3 \Rightarrow \frac{dV}{dt}=4\pi r^2\frac{dr}{dt}\).

Move mouse / drag: point on \(f(x)=\sin x\) Derivative \(f'(x)=\cos x\) = 1.000

GNU Octave

% symbolic derivative
pkg load symbolic
syms x
f = sin(x)^2
df = diff(f, x)      % 2*sin(x)*cos(x)

% numeric derivative
h = 1e-6;
df_num = @(x) (feval(f, x+h) - feval(f, x-h))/(2*h);
fplot(df, [-2*pi, 2*pi])

3. Integral Calculus

The definite integral is the limit of Riemann sums — signed area under a curve:

$$ \int_a^b f(x)\,dx = \lim_{n\to\infty} \sum_{i=1}^{n} f(x_i^*)\Delta x $$
n = 12 Left sum ≈ Exact = 2

Fundamental Theorem of Calculus

1) If \(F(x)=\int_a^x f(t)dt\), then \(F'(x)=f(x)\). 2) \(\int_a^b f(x)dx = F(b)-F(a)\) where \(F'=f\). Differentiation and integration are inverses.

Techniques

Substitution: \(\int f(g(x))g'(x)dx = \int f(u)du\). Integration by parts: \(\int u\,dv = uv - \int v\,du\).

% numeric integration
x = linspace(0, pi, 2000);
f = sin(x);
area = trapz(x, f)   % ≈ 2

% symbolic
pkg load symbolic
syms x
int(sin(x), 0, pi)   % 2
int(x*exp(x), x)     % exp(x)*(x-1)

4. Functions of Several Variables

For \(z = f(x,y)\), the graph lives in \(\mathbb{R}^3\). We visualize it with level curves (contours) where \(f(x,y)=c\).

Move mouse: shows \(f(x,y)=x^2+y^2\)

Color = height (dark low, light high). White circles are level curves. This is a paraboloid.

5. Partial Derivatives and Gradient

Hold one variable constant, differentiate:

$$ f_x = \frac{\partial f}{\partial x} = \lim_{h\to0}\frac{f(x+h,y)-f(x,y)}{h},\quad f_y = \frac{\partial f}{\partial y} $$

The gradient \(\nabla f = \langle f_x, f_y\rangle\) points in the direction of steepest ascent and is orthogonal to level curves.

Move to see ∇f
pkg load symbolic
syms x y
f = x^2 + y^2
grad = [diff(f,x), diff(f,y)]   % [2*x, 2*y]

% quiver plot
[X,Y] = meshgrid(-2:0.4:2);
U = 2*X; V = 2*Y;
quiver(X,Y,U,V); axis equal

6. Optimization in 2D

Critical points: solve \(f_x=0,\; f_y=0\). Second-derivative test:

$$ D = f_{xx}f_{yy} - (f_{xy})^2 $$

\(D>0, f_{xx}>0\) → local min; \(D>0, f_{xx}<0\) → local max; \(D<0\) → saddle.

Lagrange multipliers for constraint \(g(x,y)=c\): solve \(\nabla f = \lambda \nabla g\) and \(g=c\).

θ = 0.79 f=xy =

Maximize \(f=xy\) subject to \(x^2+y^2=1\). Max occurs when ∇f is parallel to ∇g (at 45°).

pkg load symbolic
syms x y lambda
f = x*y; g = x^2 + y^2 - 1;
L = f - lambda*g;
sol = solve([diff(L,x)==0, diff(L,y)==0, g==0], [x,y,lambda])
% Solutions: (±√2/2, ±√2/2)

7. Multiple Integrals

Double integral over rectangle: \(\iint_R f(x,y)\,dA\). Fubini's theorem allows iterated integrals:

$$ \int_a^b\int_c^d f(x,y)\,dy\,dx = \int_c^d\int_a^b f(x,y)\,dx\,dy $$
8 8 Volume ≈

Riemann sum for \(f(x,y)=1-0.4(x^2+y^2)\) over \([-1,1]^2\). Color = height.

% Octave double integral
f = @(x,y) 1 - 0.4*(x.^2 + y.^2);
dblquad(f, -1,1,-1,1)   % ≈ 2.933

% using integral2
integral2(f, -1,1,-1,1)

8. Vector Calculus

A vector field \(\mathbf{F}(x,y)=\langle P(x,y), Q(x,y)\rangle\) assigns a vector to each point.

Divergence \(\nabla\!\cdot\!\mathbf{F}=P_x+Q_y\)
source (+) / sink (−)
Curl (2D) \(\nabla\times\mathbf{F}=Q_x-P_y\)
rotation
Gradient Field \(\mathbf{F}=\nabla f\)
conservative
Field: F = ⟨-y, x⟩ (pure rotation) curl = 2, div = 0

The big theorems connect derivatives to boundaries:

% Octave: divergence and curl on grid
[X,Y] = meshgrid(-2:0.3:2);
P = -Y; Q = X;           % F = <-y, x>
quiver(X,Y,P,Q); axis equal

% analytic
div = 0 + 0;             % Px + Qy = 0
curl = 1 - (-1);         % Qx - Py = 2

From motion to fields: Single-variable calculus describes motion along a line. Multivariable calculus extends it to surfaces and space — gradients steer optimization, multiple integrals measure mass and volume, and vector calculus describes fluids, electromagnetism, and flow. The limit remains the engine underneath.