# Calculus in Technical Documentation — Derivatives and Integrals

> Master calculus notation in technical docs with KaTeX. Learn derivatives, integrals, limits, and differential equations for software, physics, and engineering documentation.

## Introduction

Calculus is the mathematical foundation for describing change and accumulation. Whether you're documenting machine learning algorithms, physics simulations, financial models, or engineering systems, calculus notation appears everywhere in technical documentation.

This guide covers how to express derivatives, integrals, limits, and differential equations using KaTeX in your technical documentation. You'll learn the standard notation conventions and see practical examples from software engineering, physics, and data science.

> **Prerequisites:** This guide assumes familiarity with basic KaTeX syntax. If you're new to KaTeX, start with our [KaTeX Syntax Quick Reference](/docs/math/notation/katex-syntax) first.

## Derivatives

Derivatives measure the rate of change of a function. There are several notation styles, each suited to different contexts in technical documentation.

### Leibniz Notation

Leibniz notation explicitly shows the variable of differentiation, making it ideal for physics and engineering documentation where multiple variables are involved.

```markdown

First derivative:
$$
\\frac{dy}{dx}
$$

Second derivative:
$$
\\frac{d^2y}{dx^2}
$$

nth derivative:
$$
\\frac{d^n y}{dx^n}
$$

Derivative of a specific function:
$$
\\frac{d}{dx}\\left(x^3 + 2x\\right) = 3x^2 + 2
$$

```

### Prime Notation (Lagrange)

Prime notation is compact and commonly used in pure mathematics and algorithm analysis where the independent variable is clear from context.

```markdown

First derivative: $f'(x)$

Second derivative: $f''(x)$

Third derivative: $f'''(x)$

Higher derivatives: $f^{(n)}(x)$

Example - velocity and acceleration:
$$
\\text{Position: } s(t), \\quad \\text{Velocity: } s'(t), \\quad \\text{Acceleration: } s''(t)
$$

```

### Dot Notation (Newton)

Dot notation is standard in physics for time derivatives, particularly in mechanics and dynamics.

```markdown

First time derivative: $\\dot{x}$

Second time derivative: $\\ddot{x}$

Newton's second law:
$$
F = m\\ddot{x}
$$

Velocity and acceleration:
$$
v = \\dot{x}, \\quad a = \\ddot{x}
$$

```

### Operator Notation

The differential operator D is useful when discussing derivatives abstractly or in differential equations.

```markdown

Differential operator:
$$
D = \\frac{d}{dx}
$$

Applied to a function:
$$
Df = \\frac{df}{dx}, \\quad D^2f = \\frac{d^2f}{dx^2}
$$

Linear differential equation:
$$
(D^2 + 3D + 2)y = 0
$$

```

## Partial Derivatives

Partial derivatives are essential for documenting multivariable functions, which appear frequently in machine learning (gradient descent), physics (field equations), and optimization problems.

```markdown

First partial derivatives:
$$
\\frac{\\partial f}{\\partial x}, \\quad \\frac{\\partial f}{\\partial y}
$$

Second partial derivatives:
$$
\\frac{\\partial^2 f}{\\partial x^2}, \\quad \\frac{\\partial^2 f}{\\partial y^2}
$$

Mixed partial derivatives:
$$
\\frac{\\partial^2 f}{\\partial x \\partial y}
$$

Example - gradient of a function:
$$
f(x, y) = x^2 + xy + y^2
$$

$$
\\nabla f = \\left(\\frac{\\partial f}{\\partial x}, \\frac{\\partial f}{\\partial y}\\right) = (2x + y, x + 2y)
$$

```

### Subscript Notation

Subscript notation is a compact alternative commonly used in physics and engineering documentation.

```markdown

Partial derivatives:
$$
f_x = \\frac{\\partial f}{\\partial x}, \\quad f_y = \\frac{\\partial f}{\\partial y}
$$

Second partials:
$$
f_{xx} = \\frac{\\partial^2 f}{\\partial x^2}, \\quad f_{xy} = \\frac{\\partial^2 f}{\\partial x \\partial y}
$$

Heat equation example:
$$
u_t = \\alpha u_{xx}
$$

```

## Gradient, Divergence, and Curl

Vector calculus operators are fundamental in physics documentation, particularly for electromagnetic fields, fluid dynamics, and machine learning optimization.

```markdown

Gradient (scalar to vector):
$$
\\nabla f = \\left(\\frac{\\partial f}{\\partial x}, \\frac{\\partial f}{\\partial y}, \\frac{\\partial f}{\\partial z}\\right)
$$

Divergence (vector to scalar):
$$
\\nabla \\cdot \\vec{F} = \\frac{\\partial F_x}{\\partial x} + \\frac{\\partial F_y}{\\partial y} + \\frac{\\partial F_z}{\\partial z}
$$

Curl (vector to vector):
$$
\\nabla \\times \\vec{F} = \\begin{vmatrix}
\\hat{i} & \\hat{j} & \\hat{k} \\\\
\\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\
F_x & F_y & F_z
\\end{vmatrix}
$$

Laplacian:
$$
\\nabla^2 f = \\frac{\\partial^2 f}{\\partial x^2} + \\frac{\\partial^2 f}{\\partial y^2} + \\frac{\\partial^2 f}{\\partial z^2}
$$

```

## Integrals

Integrals represent accumulation and are used extensively in probability theory, physics, and signal processing documentation.

### Indefinite Integrals

```markdown

Basic indefinite integral:
$$
\\int f(x) \\, dx
$$

Power rule:
$$
\\int x^n \\, dx = \\frac{x^{n+1}}{n+1} + C \\quad (n \\neq -1)
$$

Exponential:
$$
\\int e^x \\, dx = e^x + C
$$

Trigonometric:
$$
\\int \\sin(x) \\, dx = -\\cos(x) + C
$$

```

> **Spacing Tip:** Always use `\,` before `dx` to add proper spacing: `$\int f(x) \, dx$` looks better than `$\int f(x) dx$`.

### Definite Integrals

```markdown

Definite integral:
$$
\\int_{a}^{b} f(x) \\, dx
$$

Fundamental theorem of calculus:
$$
\\int_{a}^{b} f'(x) \\, dx = f(b) - f(a)
$$

Area under a curve:
$$
A = \\int_{0}^{2} x^2 \\, dx = \\left[\\frac{x^3}{3}\\right]_0^2 = \\frac{8}{3}
$$

Probability density:
$$
P(a \\leq X \\leq b) = \\int_{a}^{b} f(x) \\, dx
$$

```

### Multiple Integrals

```markdown

Double integral:
$$
\\iint_D f(x, y) \\, dA
$$

Triple integral:
$$
\\iiint_V f(x, y, z) \\, dV
$$

Iterated integral:
$$
\\int_{0}^{1} \\int_{0}^{x} xy \\, dy \\, dx
$$

Volume calculation:
$$
V = \\iint_R f(x, y) \\, dA = \\int_{a}^{b} \\int_{c}^{d} f(x, y) \\, dy \\, dx
$$

```

### Line and Surface Integrals

```markdown

Line integral (scalar):
$$
\\int_C f \\, ds
$$

Line integral (vector):
$$
\\int_C \\vec{F} \\cdot d\\vec{r}
$$

Closed line integral:
$$
\\oint_C \\vec{F} \\cdot d\\vec{r}
$$

Surface integral:
$$
\\iint_S \\vec{F} \\cdot d\\vec{S}
$$

Closed surface integral:
$$
\\oiint_S \\vec{F} \\cdot d\\vec{S}
$$

```

## Limits

Limits are foundational to calculus and appear in algorithm complexity analysis, convergence proofs, and asymptotic behavior documentation.

```markdown

Basic limit:
$$
\\lim_{x \\to a} f(x)
$$

One-sided limits:
$$
\\lim_{x \\to a^+} f(x), \\quad \\lim_{x \\to a^-} f(x)
$$

Limit at infinity:
$$
\\lim_{x \\to \\infty} \\frac{1}{x} = 0
$$

Limit definition of derivative:
$$
f'(x) = \\lim_{h \\to 0} \\frac{f(x + h) - f(x)}{h}
$$

Limit definition of e:
$$
e = \\lim_{n \\to \\infty} \\left(1 + \\frac{1}{n}\\right)^n
$$

```

### Limits in Series

```markdown

Sequence limit:
$$
\\lim_{n \\to \\infty} a_n = L
$$

Infinite series:
$$
\\sum_{n=1}^{\\infty} a_n = \\lim_{N \\to \\infty} \\sum_{n=1}^{N} a_n
$$

Geometric series:
$$
\\sum_{n=0}^{\\infty} r^n = \\frac{1}{1-r} \\quad (|r| < 1)
$$

Taylor series:
$$
f(x) = \\sum_{n=0}^{\\infty} \\frac{f^{(n)}(a)}{n!}(x-a)^n
$$

```

## Differential Equations

Differential equations model dynamic systems and appear throughout physics, engineering, and computational science documentation.

### Ordinary Differential Equations

```markdown

First-order ODE:
$$
\\frac{dy}{dx} = f(x, y)
$$

Second-order ODE:
$$
\\frac{d^2y}{dx^2} + p(x)\\frac{dy}{dx} + q(x)y = g(x)
$$

Simple harmonic oscillator:
$$
\\frac{d^2x}{dt^2} + \\omega^2 x = 0
$$

Solution:
$$
x(t) = A\\cos(\\omega t) + B\\sin(\\omega t)
$$

```

### Partial Differential Equations

```markdown

Heat equation:
$$
\\frac{\\partial u}{\\partial t} = \\alpha \\nabla^2 u
$$

Wave equation:
$$
\\frac{\\partial^2 u}{\\partial t^2} = c^2 \\nabla^2 u
$$

Laplace equation:
$$
\\nabla^2 \\phi = 0
$$

Schrödinger equation:
$$
i\\hbar \\frac{\\partial \\Psi}{\\partial t} = -\\frac{\\hbar^2}{2m}\\nabla^2\\Psi + V\\Psi
$$

```

## Applications in Technical Documentation

Here are practical examples of calculus notation in common technical documentation scenarios.

### Machine Learning: Gradient Descent

```markdown

**Gradient Descent Update Rule**

The parameters $\\theta$ are updated iteratively:

$$
\\theta_{n+1} = \\theta_n - \\alpha \\nabla J(\\theta_n)
$$

where:
- $\\alpha$ is the learning rate
- $\\nabla J(\\theta)$ is the gradient of the cost function

For a single parameter:
$$
\\theta_{n+1} = \\theta_n - \\alpha \\frac{\\partial J}{\\partial \\theta}
$$

**Cost Function Gradient**

For mean squared error:
$$
J(\\theta) = \\frac{1}{2m}\\sum_{i=1}^{m}(h_\\theta(x^{(i)}) - y^{(i)})^2
$$

$$
\\frac{\\partial J}{\\partial \\theta_j} = \\frac{1}{m}\\sum_{i=1}^{m}(h_\\theta(x^{(i)}) - y^{(i)})x_j^{(i)}
$$

```

### Physics: Kinematics

```markdown

**Position, Velocity, and Acceleration**

Position as a function of time:
$$
x(t)
$$

Velocity (first derivative of position):
$$
v(t) = \\frac{dx}{dt} = \\dot{x}
$$

Acceleration (second derivative of position):
$$
a(t) = \\frac{dv}{dt} = \\frac{d^2x}{dt^2} = \\ddot{x}
$$

**Constant Acceleration**

$$
\\begin{aligned}
v(t) &= v_0 + at \\\\
x(t) &= x_0 + v_0 t + \\frac{1}{2}at^2 \\\\
v^2 &= v_0^2 + 2a(x - x_0)
\\end{aligned}
$$

```

### Statistics: Probability Distributions

```markdown

**Probability Density Function**

For a continuous random variable $X$:
$$
P(a \\leq X \\leq b) = \\int_{a}^{b} f(x) \\, dx
$$

**Normal Distribution**

$$
f(x) = \\frac{1}{\\sigma\\sqrt{2\\pi}} e^{-\\frac{(x-\\mu)^2}{2\\sigma^2}}
$$

**Expected Value**

$$
E[X] = \\int_{-\\infty}^{\\infty} x \\cdot f(x) \\, dx
$$

**Variance**

$$
\\text{Var}(X) = E[X^2] - (E[X])^2 = \\int_{-\\infty}^{\\infty} (x - \\mu)^2 f(x) \\, dx
$$

```

### Algorithm Analysis: Big O

```markdown

**Asymptotic Analysis**

Big O notation using limits:
$$
f(n) = O(g(n)) \\iff \\lim_{n \\to \\infty} \\frac{f(n)}{g(n)} < \\infty
$$

**Summation to Integral Approximation**

For large $n$:
$$
\\sum_{i=1}^{n} f(i) \\approx \\int_{1}^{n} f(x) \\, dx
$$

Example - sum of squares:
$$
\\sum_{i=1}^{n} i^2 \\approx \\int_{1}^{n} x^2 \\, dx = \\frac{n^3}{3} = O(n^3)
$$

**Stirling's Approximation**

$$
n! \\approx \\sqrt{2\\pi n}\\left(\\frac{n}{e}\\right)^n
$$

$$
\\ln(n!) \\approx n\\ln(n) - n
$$

```

## Best Practices

> **Choose Notation Consistently:** Pick one notation style (Leibniz, prime, or dot) and use it consistently throughout your document. Mix only when conventions demand it (e.g., dot notation for time derivatives in physics).

> **Use Display Math for Complex Expressions:** Complex derivatives and integrals are much easier to read in display mode. Reserve inline math for simple expressions like $f'(x)$ or $\int f \, dx$.

> **Add Context and Definitions:** Always define your variables. Write "where $x$ is position and $t$ is time" after introducing equations. This helps readers unfamiliar with your specific domain.

> **Use Aligned Environments for Multi-Step Derivations:** When showing step-by-step calculations, use the `aligned` environment to align equals signs, making the logic flow clear.

> **Include Units Where Appropriate:** In physics and engineering docs, include units using `\text{'{}'}`: `$v = 10 \text{'{ m/s}'}$`

## Common Mistakes

> **Missing Spacing in Integrals:** Always add `\,` before differentials. Write `$\int f(x) \, dx$` not `$\int f(x)dx$`.

> **Incorrect Partial Derivative Symbol:** Use `\partial` for partial derivatives, not `d`. Write `$\frac{'{\\partial f}{\\partial x}'}$` not `$\frac{'{df}{dx}'}$` for multivariable functions.

> **Forgetting Limits on Operators:** Large operators need limits. Write `$\lim_{'x \\to 0'}$` not just `$\lim$`, and `$\sum_{'i=1'}^{'n'}$` not just `$\sum$`.

> **Inconsistent Vector Notation:** Choose one style for vectors: `$\vec{'{v}'}$`, `$\mathbf{'{v}'}$`, or bold. Don't mix them in the same document.

> **Missing Parentheses in Function Arguments:** Write `$\sin(x)$` not `$\sin x$` when the argument is complex. This prevents ambiguity in expressions like `$\sin(x+y)$`.

## Quick Reference

| Operation | KaTeX Syntax | Result |
| --- | --- | --- |
| Derivative (Leibniz) | `\frac{'{dy}{dx}'}` | $\frac{'{dy}{dx}'}$ |
| Derivative (Prime) | f&apos;(x) | $f&apos;(x)$ |
| Partial Derivative | `\frac{'\\partial f'}
                  {'{\\partial x}'}` | $\frac{'\\partial f'} {'{\\partial x}'}$ |
| Gradient | `\nabla f` | $\nabla f$ |
| Indefinite Integral | `\int f(x) \, dx` | $\int f(x) \, dx$ |
| Definite Integral | `\int_{'{a}'}^{'{b}'} f(x) \, dx` | $\int_{'{a}'}^{'{b}'} f(x) \, dx$ |
| Double Integral | `\iint_D f \, dA` | $\iint_D f \, dA$ |
| Limit | `\lim_{'{x \\to a}'} f(x)` | $\lim_{'{x \\to a}'} f(x)$ |
| Time Derivative | `\dot{'{x}'}, \ddot{'{x}'}` | $\dot{'{x}'}$, $\ddot{'{x}'}$ |
| Laplacian | `\nabla^2 f` | $\nabla^2 f$ |
