# Calculus

## Differential Calculus

### Derivative

$\left.\frac{d f(x)}{dx}\right|_{x = x_0} = \lim_{\Delta x \to 0} \frac{f(x_0 + \Delta x) - f(x_0)}{\Delta x}$

This is the derivative of $$f(x)$$ with respect to $$x$$, evaluated at point $$x_0$$.

The point of evaluation is often omitted to more succinctly write:

$\frac{d f(x)}{dx} = \lim_{\Delta x \to 0} \frac{f(x + \Delta x) - f(x)}{\Delta x}$

### Linearity

Constants come out:

$\frac{d(a f(x))}{dx} = a \frac{d f(x)}{dx}$

Derivative of the sum is the sum of derivatives:

$\frac{d}{dx}(f(x) + g(x)) = \frac{d f(x)}{dx} + \frac{d g(x)}{dx}$

### Product Rule

$\frac{d}{dx} (f(x) g(x)) = f(x) \frac{d g(x)}{dx} + g(x) \frac{d f(x)}{dx}$

Derivation:

\begin{align} \frac{d (f(x) g(x))}{dx} &= \lim_{\Delta x \to 0} \frac{f(x + \Delta x)g(x + \Delta x) - f(x)g(x)}{\Delta x} \\ \\ &= \lim_{\Delta x \to 0} \frac{f(x + \Delta x)g(x + \Delta x) - f(x + \Delta x)g(x) + f(x + \Delta x)g(x) - f(x)g(x)}{\Delta x} \\ \\ &= \lim_{\Delta x \to 0} f(x + \Delta x) \cdot \lim_{\Delta x \to 0} \frac{g(x + \Delta x) - g(x)}{\Delta x} + \lim_{\Delta x \to 0} g(x) \cdot \lim_{\Delta x \to 0} \frac{f(x + \Delta x) - f(x)}{\Delta x} \\ \\ &= f(x) \frac{d g(x)}{dx} + g(x) \frac{d f(x)}{dx} \end{align}

The trick is to subtract and add the same expression in step 2.

Then, because of linearity of limit, the limit of the sum becomes the sum of limits, and the limit of the product, the product of limits.

Finally, note that $$\lim_{\Delta x \to 0} \; f(x + \Delta x)$$ is just $$f(x)$$.

### Product Differential

Multiplying the product rule by $$\Delta x$$ gives us the product differential:

$d (f(x)g(x)) = f(x) dg(x) + g(x) df(x)$

### Chain Rule

$\left.\frac{d f(g(x))}{dx}\right|_{x_0} = \left.\frac{d f(g(x))}{d g(x)}\right|_{g(x_0)} \cdot \left.\frac{d g(x)}{dx}\right|_{x_0}$

More commonly, using Leibnizâ€™s notation, define $$y = g(x)$$ and $$z = f(y)$$, then:

$\left.\frac{dz}{dx}\right|_{x_0} = \left.\frac{dz}{dy}\right|_{y(x_0)} \cdot \left.\frac{dy}{dx}\right|_{x_0}$

### Monomial Derivative

We can derive the derivative for a monomial using induction and the product rule.

Starting with a few base cases:

\begin{align} \frac{d x^0}{dx} &= \frac{d 1}{dx} = 0 \\ \\ \frac{dx}{dx} &= 1 \\ \\ \frac{d x^2}{dx} &= x \cdot \frac{dx}{dx} + x \cdot \frac{dx}{dx} = x \cdot 1 + x \cdot 1 = 2x \\ \\ \frac{d x^3}{dx} &= \frac{d (x^2 \cdot x)}{dx} = x^2 \cdot 1 + x \cdot 2x = 3x^2 \end{align}

For the inductive step, assume $$\frac{d x^n}{dx} = n x^{n-1}$$ by hypothesis of induction, then derive the result for $$n+1$$:

\begin{align} \frac{d x^{n+1}}{dx} &= \frac{d (x^n \cdot x)}{dx} \\ &= x^n \cdot \frac{dx}{dx} + x \cdot \frac{d x^n}{dx} \\ &= x^n + x \cdot nx^{n-1} \\ &= x^n + nx^n \\ &= (n+1)x^n \end{align}

### Polynomial Derivative

The derivative distributes over the sum, and then we just apply the general monomial derivative:

\begin{align}\frac{d}{dx} (a_nx^n + a_{n-1}x^{n-1} + \ldots + a_0) \\ \\ = \frac{d (a_nx^n)}{dx} + \frac{d (a_{n-1}x^{n-1})}{dx} + \ldots + \frac{d a_0}{dx} \end{align}

### Example: Derivative of $$x^2$$

We can differentiate $$x^2$$ in a number of ways:

1. Through direct application.
2. Product rule.
3. From the general monomial derivative result.

#### Direct application

\begin{align} \frac{d x^2}{dx} &= \lim_{\Delta x \to 0} \frac{(x + \Delta x)^2 - x^2}{\Delta x} \\ \\ &= \lim_{\Delta x \to 0} \frac{(x^2 + \Delta x^2 + 2 x \Delta x) - x^2}{\Delta x} \\ \\ &= \lim_{\Delta x \to 0} \frac{\Delta x^2 + 2 x \Delta x}{\Delta x} \\ \\ &= \lim_{\Delta x \to 0} \Delta x + 2x \\ \\ &= 2x \end{align}

#### Product rule

\begin{align} \frac{d x^2}{dx} &= \frac{d (x \cdot x)}{dx} \\ \\ &= x \cdot \frac{dx}{dx} + x \cdot \frac{dx}{dx} \\ \\ &= x \cdot 1 + x \cdot 1 \\ \\ &= 2x \end{align}

## Integral Calculus

### Definite Integral

$F(x) = \int_a^b f(x) dx$

$$f(x)$$ is the derivative of $$F(x)$$; $$F(x)$$ is the anti-derivative of $$f(x)$$.

The integral symbol is notation for an infinite sum in the limit that the number of terms approaches $$\infty$$ and the differential approaches $$0$$. Below, we sum $$f(x) \Delta x$$ in the range $$[a,b]$$ using $$N$$ terms:

$\lim_{\Delta N \to \infty} \sum_{n=1}^N \, f(a + n \cdot \Delta x) \Delta x = \int_a^b f(x) dx$

### Area Interpretation

$$F(x)$$ is the area under the curve $$f(x)$$ in the range $$[a,b]$$. $$f(x)$$ is the derivative of $$F(x)$$, the function that represents the area beneath it.

Consider a curve $$f(x)$$ and a section of the curve $$[a,b]$$. Then:

$\Delta A = f(x) \Delta x$

Is the area of the rectangle spanning $$[a,b]$$, which approximates the area under the curve.

We can better approximate the area under the curve by splitting the rectangle into smaller ones and adding each of their areas (a Riemann sum):

$A \approx \sum_{n=1}^N \, f(a + n \cdot \Delta x) \Delta x$

In the limit as $$N \to \infty$$ and $$\Delta x \to 0$$, the rectangles become infinitesimally small and we get the exact area under the curve:

\begin{align} A &= \lim_{\Delta N \to \infty} \sum_{n=1}^N \, f(a + n \cdot \Delta x) \Delta x \\ \\ &= \int_a^b f(x) dx \\ \\ &= F(x) \end{align}

### Algebra

Another approach to get to $$F(x)$$ is to start with $$f(x)$$ which, by definition, is the derivative of $$F(x)$$:

\begin{align} \frac{d F(x)}{dx} &= f(x) \\ \\ d F(x) &= f(x) dx \end{align}

Take integrals of both sides:

\begin{align} \int_a^b d F(x) &= \int_a^b f(x) dx \\ F(x) &= \int_a^b f(x) dx \end{align}

### Integration by Parts

$f(x) g(x) = \int f(x) \frac{d g(x)}{dx} dx + \int g(x) \frac{d f(x)}{dx} dx$

Derivation:

Recall the product rule:

$\frac{d}{dx} f(x)g(x) = f(x) \frac{d g(x)}{dx} + g(x) \frac{d f(x)}{dx}$

Take integrals on both sides:

\begin{align} \int \frac{d}{dx} (f(x)g(x)) dx &= \int (f(x) \frac{d g(x)}{dx} + g(x) \frac{d f(x)}{dx}) dx \\ \\ f(x) g(x) &= \int (f(x) \frac{d g(x)}{dx} + g(x) \frac{d f(x)}{dx}) dx \\ \\ &= \int f(x) \frac{d g(x)}{dx} dx + \int g(x) \frac{d f(x)}{dx} dx \end{align}

This result can be re-arranged to yield:

\begin{align} \int f(x) \frac{d g(x)}{dx} dx &= f(x) g(x) - \int g(x) \frac{d f(x)}{dx} dx \\ \\ \int g(x) \frac{d f(x)}{dx} dx &= f(x) g(x) - \int f(x) \frac{d g(x)}{dx} dx \end{align}

### Integral of a Monomial

$F(x) = \int x^n dx$

From the derivative of a monomial:

\begin{align} \frac{d (x^{n+1})}{dx} &= (n+1) x^n \\ \\ \frac{1}{n+1} \frac{d (x^{n+1})}{dx} &= x^n \end{align}

Therefore:

\begin{align} F(x) &= \int x^n dx \\ \\ &= \int \frac{1}{n+1} \frac{d (x^{n+1})}{dx} dx \\ \\ &= \frac{1}{n+1} \int d (x^{n+1}) \\ \\ &= \frac{1}{n+1} x^{n+1} \end{align}