← Math|28 of 100
Calculus

Integration Fundamentals

Master definite and indefinite integrals, Fundamental Theorem of Calculus, integration techniques, numerical methods, and applications in probability and machine learning.

📂 Integration📖 Lesson 28 of 100🎓 Free Course

Advertisement

Integration Fundamentals

â„šī¸ Why It Matters

Integration is the reverse operation of differentiation and one of the two pillars of calculus. While derivatives measure rates of change, integrals accumulate quantities: areas under curves, volumes of solids, total probability, and expected values. In machine learning, integration is indispensable — probability density functions are normalized by integrating to 1, expected values are computed as integrals, Bayesian inference requires marginalizing over posterior distributions, and variational inference approximates intractable integrals. Every time you compute the probability that a continuous random variable falls in a range, you are performing integration. Every time you sample from a distribution or estimate an expectation, integration is happening underneath. Mastering integration means understanding the mathematical foundation behind probability, statistics, and the training of probabilistic models.


What is an Integral

DfIndefinite Integral (Antiderivative)

The indefinite integral of a function f(x)f(x) is a family of functions F(x)F(x) whose derivative is f(x)f(x). It is written âˆĢf(x) dx=F(x)+C\int f(x)\,dx = F(x) + C, where CC is an arbitrary constant of integration representing the fact that infinitely many antiderivatives differ only by a constant.

DfDefinite Integral

The definite integral of f(x)f(x) from aa to bb is the signed area between the curve y=f(x)y = f(x) and the xx-axis over the interval [a,b][a, b]. It is defined as the limit of Riemann sums:

Riemann Sum Definition

âˆĢabf(x) dx=lim⁥n→∞∑i=1nf(xi∗)Δx\int_a^b f(x)\,dx = \lim_{n \to \infty} \sum_{i=1}^{n} f(x_i^*) \Delta x

Here,

  • Δx\Delta x=Width of each subinterval: (b - a) / n
  • xi∗x_i^*=A sample point in the i-th subinterval
  • f(xi∗)f(x_i^*)=Function value at the sample point
  • a,ba, b=The lower and upper limits of integration

💡 Definite vs Indefinite

An indefinite integral produces a family of functions (F(x)+CF(x) + C), while a definite integral produces a number (the signed area). The Fundamental Theorem of Calculus connects them: the definite integral equals the antiderivative evaluated at the bounds.

âš ī¸ Not All Functions Have Elementary Antiderivatives

Many common functions — such as e−x2e^{-x^2}, sin⁡xx\frac{\sin x}{x}, and sin⁡x\sqrt{\sin x} — do not have closed-form antiderivatives in terms of elementary functions. For these, we rely on numerical integration or special functions (e.g., the error function erf(x)\text{erf}(x)).


Fundamental Theorem of Calculus

ThFundamental Theorem of Calculus (Part 1)

If ff is continuous on [a,b][a, b] and F(x)=âˆĢaxf(t) dtF(x) = \int_a^x f(t)\,dt, then FF is differentiable on (a,b)(a, b) and F′(x)=f(x)F'(x) = f(x). In other words, differentiation undoes integration.

ThFundamental Theorem of Calculus (Part 2)

If ff is continuous on [a,b][a, b] and FF is any antiderivative of ff (i.e., F′(x)=f(x)F'(x) = f(x)), then:

Fundamental Theorem of Calculus

âˆĢabf(x) dx=F(b)−F(a)\int_a^b f(x)\,dx = F(b) - F(a)

Here,

  • f(x)f(x)=The integrand — the function being integrated
  • F(x)F(x)=An antiderivative of f, where F'(x) = f(x)
  • aa=The lower limit of integration
  • bb=The upper limit of integration
  • F(b)−F(a)F(b) - F(a)=The net change of F over [a, b]

â„šī¸ Intuition

Part 1 says that if you build a function by integrating ff from a fixed point aa to a variable point xx, the rate at which this accumulated area grows is exactly f(x)f(x). Part 2 says that to compute the accumulated area, you only need any antiderivative — evaluate it at the top bound and subtract its value at the bottom bound. This transforms the hard problem of summing infinitely many infinitesimal contributions into the easy problem of evaluating a function at two points.

📝Applying the Fundamental Theorem

Problem: Compute âˆĢ02(3x2+2x) dx\int_0^2 (3x^2 + 2x)\,dx.

💡Solution

Find an antiderivative: F(x)=x3+x2F(x) = x^3 + x^2 (since F′(x)=3x2+2xF'(x) = 3x^2 + 2x).

Evaluate at the bounds: F(2)−F(0)=(8+4)−(0+0)=12F(2) - F(0) = (8 + 4) - (0 + 0) = 12.

The area under 3x2+2x3x^2 + 2x from x=0x = 0 to x=2x = 2 is 1212.


Properties of Definite Integrals

PropertyFormulaDescription
Reversing boundsâˆĢabf(x) dx=−âˆĢbaf(x) dx\int_a^b f(x)\,dx = -\int_b^a f(x)\,dxSwapping limits negates the integral
AdditivityâˆĢabf(x) dx=âˆĢacf(x) dx+âˆĢcbf(x) dx\int_a^b f(x)\,dx = \int_a^c f(x)\,dx + \int_c^b f(x)\,dxSplit at any intermediate point cc
LinearityâˆĢab[Îąf(x)+βg(x)] dx=ÎąâˆĢabf(x) dx+βâˆĢabg(x) dx\int_a^b [\alpha f(x) + \beta g(x)]\,dx = \alpha\int_a^b f(x)\,dx + \beta\int_a^b g(x)\,dxConstants factor out, integrals add
Zero-widthâˆĢaaf(x) dx=0\int_a^a f(x)\,dx = 0Integrating over a point gives zero
PositivityIf f(x)â‰Ĩ0f(x) \geq 0 on [a,b][a,b], then âˆĢabf(x) dxâ‰Ĩ0\int_a^b f(x)\,dx \geq 0Non-negative functions have non-negative integrals
ComparisonIf f(x)≤g(x)f(x) \leq g(x) on [a,b][a,b], then âˆĢabf(x) dx≤âˆĢabg(x) dx\int_a^b f(x)\,dx \leq \int_a^b g(x)\,dxInequality preserved under integration
Triangle InequalityâˆŖâˆĢabf(x) dxâˆŖâ‰¤âˆĢabâˆŖf(x)âˆŖâ€‰dx\left|\int_a^b f(x)\,dx\right| \leq \int_a^b |f(x)|\,dxThe integral of the absolute value bounds the absolute value of the integral

Basic Integration Rules

The following rules allow us to integrate complex functions by breaking them into simpler parts.

RuleFormulaExample
ConstantâˆĢc dx=cx+C\int c\,dx = cx + CâˆĢ5 dx=5x+C\int 5\,dx = 5x + C
Power RuleâˆĢxn dx=xn+1n+1+C\int x^n\,dx = \frac{x^{n+1}}{n+1} + C (n≠−1n \neq -1)âˆĢx3 dx=x44+C\int x^3\,dx = \frac{x^4}{4} + C
ReciprocalâˆĢ1x dx=lnâĄâˆŖxâˆŖ+C\int \frac{1}{x}\,dx = \ln|x| + CâˆĢ1x dx=lnâĄâˆŖxâˆŖ+C\int \frac{1}{x}\,dx = \ln|x| + C
ExponentialâˆĢex dx=ex+C\int e^x\,dx = e^x + CâˆĢex dx=ex+C\int e^x\,dx = e^x + C
General ExponentialâˆĢax dx=axln⁥a+C\int a^x\,dx = \frac{a^x}{\ln a} + CâˆĢ3x dx=3xln⁥3+C\int 3^x\,dx = \frac{3^x}{\ln 3} + C
SineâˆĢsin⁥x dx=−cos⁥x+C\int \sin x\,dx = -\cos x + CâˆĢsin⁥x dx=−cos⁥x+C\int \sin x\,dx = -\cos x + C
CosineâˆĢcos⁥x dx=sin⁥x+C\int \cos x\,dx = \sin x + CâˆĢcos⁥x dx=sin⁥x+C\int \cos x\,dx = \sin x + C
SecantâˆĢsec⁥2x dx=tan⁥x+C\int \sec^2 x\,dx = \tan x + CâˆĢsec⁥2x dx=tan⁥x+C\int \sec^2 x\,dx = \tan x + C
CosecantâˆĢcsc⁥2x dx=−cot⁥x+C\int \csc^2 x\,dx = -\cot x + CâˆĢcsc⁥2x dx=−cot⁥x+C\int \csc^2 x\,dx = -\cot x + C
Secant-TangentâˆĢsec⁥xtan⁥x dx=sec⁥x+C\int \sec x \tan x\,dx = \sec x + CâˆĢsec⁥xtan⁥x dx=sec⁥x+C\int \sec x \tan x\,dx = \sec x + C
Cosecant-CotangentâˆĢcsc⁥xcot⁥x dx=−csc⁥x+C\int \csc x \cot x\,dx = -\csc x + CâˆĢcsc⁥xcot⁥x dx=−csc⁥x+C\int \csc x \cot x\,dx = -\csc x + C
Inverse SineâˆĢ11−x2 dx=arcsin⁥x+C\int \frac{1}{\sqrt{1-x^2}}\,dx = \arcsin x + CâˆĢ11−x2 dx=arcsin⁥x+C\int \frac{1}{\sqrt{1-x^2}}\,dx = \arcsin x + C
Inverse TangentâˆĢ11+x2 dx=arctan⁥x+C\int \frac{1}{1+x^2}\,dx = \arctan x + CâˆĢ11+x2 dx=arctan⁥x+C\int \frac{1}{1+x^2}\,dx = \arctan x + C
Hyperbolic SineâˆĢsinh⁥x dx=cosh⁥x+C\int \sinh x\,dx = \cosh x + CâˆĢsinh⁥x dx=cosh⁥x+C\int \sinh x\,dx = \cosh x + C
Hyperbolic CosineâˆĢcosh⁥x dx=sinh⁥x+C\int \cosh x\,dx = \sinh x + CâˆĢcosh⁥x dx=sinh⁥x+C\int \cosh x\,dx = \sinh x + C

💡 Power Rule Exception

The power rule âˆĢxn dx=xn+1n+1+C\int x^n\,dx = \frac{x^{n+1}}{n+1} + C fails when n=−1n = -1. In that case, âˆĢx−1 dx=âˆĢ1x dx=lnâĄâˆŖxâˆŖ+C\int x^{-1}\,dx = \int \frac{1}{x}\,dx = \ln|x| + C. This is because ddxlnâĄâˆŖxâˆŖ=1x\frac{d}{dx}\ln|x| = \frac{1}{x}.


Integration by Substitution

DfIntegration by Substitution (u-substitution)

The substitution rule is the reverse of the chain rule for differentiation. If u=g(x)u = g(x) is a differentiable function whose range is an interval, and ff is continuous on that interval, then:

Substitution Rule

âˆĢf(g(x))⋅g′(x) dx=âˆĢf(u) duwhere u=g(x)\int f(g(x)) \cdot g'(x)\,dx = \int f(u)\,du \quad \text{where } u = g(x)

Here,

  • u=g(x)u = g(x)=The substitution — the inner function
  • du=g′(x)dxdu = g'(x)dx=The differential of u
  • f(g(x))⋅g′(x)f(g(x)) \cdot g'(x)=The original integrand with chain rule factor

💡 When to Use Substitution

Use substitution when the integrand contains a function and its derivative (or a constant multiple of it). Look for a "inner function" g(x)g(x) whose derivative g′(x)g'(x) appears as a factor. Common patterns: âˆĢsin⁥(cos⁥x)cos⁥x dx\int \sin(\cos x) \cos x\,dx, âˆĢxex2 dx\int xe^{x^2}\,dx, âˆĢxx2+1 dx\int \frac{x}{x^2+1}\,dx.

📝Substitution Example 1

Problem: Compute âˆĢ2xcos⁥(x2) dx\int 2x \cos(x^2)\,dx.

💡Solution

Let u=x2u = x^2, so du=2x dxdu = 2x\,dx.

âˆĢcos⁥(u) du=sin⁥(u)+C=sin⁥(x2)+C\int \cos(u)\,du = \sin(u) + C = \sin(x^2) + C.

📝Substitution Example 2

Problem: Compute âˆĢ0Ī€/2sin⁥3(x)cos⁥(x) dx\int_0^{\pi/2} \sin^3(x) \cos(x)\,dx.

💡Solution

Let u=sin⁡(x)u = \sin(x), so du=cos⁡(x) dxdu = \cos(x)\,dx.

When x=0x = 0, u=0u = 0. When x=Ī€/2x = \pi/2, u=1u = 1.

âˆĢ01u3 du=[u44]01=14\int_0^1 u^3\,du = \left[\frac{u^4}{4}\right]_0^1 = \frac{1}{4}.

âš ī¸ Don't Forget to Change the Bounds

When performing substitution on a definite integral, you must either change the limits of integration to match the new variable or back-substitute before evaluating. Forgetting to update the bounds is one of the most common errors.


Integration by Parts

DfIntegration by Parts

Integration by parts is the reverse of the product rule for differentiation. It is used to integrate products of functions:

Integration by Parts

âˆĢu dv=uv−âˆĢv du\int u\,dv = uv - \int v\,du

Here,

  • uu=The part you differentiate (choose something that simplifies)
  • dvdv=The part you integrate (choose something easy to integrate)
  • dudu=The derivative of u
  • vv=The antiderivative of dv

Definite Integral Version

âˆĢabu dv=[uv]ab−âˆĢabv du\int_a^b u\,dv = [uv]_a^b - \int_a^b v\,du

Here,

  • [uv]ab[uv]_a^b=The boundary term: u(b)v(b) - u(a)v(a)
  • âˆĢabv du\int_a^b v\,du=The remaining integral (often simpler)

💡 LIATE Rule for Choosing u

A helpful heuristic for choosing uu: Logarithmic → Inverse trig → Algebraic → Trigonometric → Exponential. Choose uu as whichever comes first in this list. The remaining factor becomes dvdv.

📝Integration by Parts Example 1

Problem: Compute âˆĢxex dx\int x e^x\,dx.

💡Solution

Let u=xu = x (algebraic), dv=ex dxdv = e^x\,dx (exponential). Then du=dxdu = dx, v=exv = e^x.

âˆĢxex dx=xex−âˆĢex dx=xex−ex+C=ex(x−1)+C\int x e^x\,dx = xe^x - \int e^x\,dx = xe^x - e^x + C = e^x(x - 1) + C.

📝Integration by Parts Example 2

Problem: Compute âˆĢln⁥x dx\int \ln x\,dx.

💡Solution

Let u=ln⁡xu = \ln x, dv=dxdv = dx. Then du=1x dxdu = \frac{1}{x}\,dx, v=xv = x.

âˆĢln⁥x dx=xln⁥x−âˆĢx⋅1x dx=xln⁥x−âˆĢ1 dx=xln⁥x−x+C\int \ln x\,dx = x\ln x - \int x \cdot \frac{1}{x}\,dx = x\ln x - \int 1\,dx = x\ln x - x + C.

📝Integration by Parts Example 3

Problem: Compute âˆĢexsin⁥x dx\int e^x \sin x\,dx.

💡Solution

Apply integration by parts twice:

Let u=sin⁡xu = \sin x, dv=ex dxdv = e^x\,dx. Then du=cos⁡x dxdu = \cos x\,dx, v=exv = e^x.

I=exsin⁥x−âˆĢexcos⁥x dxI = e^x \sin x - \int e^x \cos x\,dx

Now integrate âˆĢexcos⁥x dx\int e^x \cos x\,dx by parts again:

Let u=cos⁡xu = \cos x, dv=ex dxdv = e^x\,dx. Then du=−sin⁡x dxdu = -\sin x\,dx, v=exv = e^x.

âˆĢexcos⁥x dx=excos⁥x+âˆĢexsin⁥x dx=excos⁥x+I\int e^x \cos x\,dx = e^x \cos x + \int e^x \sin x\,dx = e^x \cos x + I

Substitute back: I=exsin⁡x−(excos⁡x+I)=ex(sin⁡x−cos⁡x)−II = e^x \sin x - (e^x \cos x + I) = e^x(\sin x - \cos x) - I

2I=ex(sin⁡x−cos⁡x)2I = e^x(\sin x - \cos x)I=ex(sin⁡x−cos⁡x)2+CI = \frac{e^x(\sin x - \cos x)}{2} + C

âš ī¸ Cyclic Integration by Parts

When integration by parts returns you to the original integral (as in the exsin⁥xe^x \sin x example), you can solve for the integral algebraically. This "cyclic" pattern occurs with products of exponentials and trigonometric functions.


Common Integrals

IntegralResultNotes
âˆĢxn dx\int x^n\,dxxn+1n+1+C\frac{x^{n+1}}{n+1} + Cn≠−1n \neq -1
âˆĢ1x dx\int \frac{1}{x}\,dxlnâĄâˆŖxâˆŖ+C\ln|x| + CThe n=−1n = -1 case
âˆĢex dx\int e^x\,dxex+Ce^x + CIts own antiderivative
âˆĢax dx\int a^x\,dxaxln⁥a+C\frac{a^x}{\ln a} + Ca>0a > 0, a≠1a \neq 1
âˆĢsin⁥x dx\int \sin x\,dx−cos⁥x+C-\cos x + C
âˆĢcos⁥x dx\int \cos x\,dxsin⁥x+C\sin x + C
âˆĢsec⁥2x dx\int \sec^2 x\,dxtan⁥x+C\tan x + C
âˆĢcsc⁥2x dx\int \csc^2 x\,dx−cot⁥x+C-\cot x + C
âˆĢsec⁥xtan⁥x dx\int \sec x \tan x\,dxsec⁥x+C\sec x + C
âˆĢcsc⁥xcot⁥x dx\int \csc x \cot x\,dx−csc⁥x+C-\csc x + C
âˆĢ11−x2 dx\int \frac{1}{\sqrt{1-x^2}}\,dxarcsin⁥x+C\arcsin x + C
âˆĢ11+x2 dx\int \frac{1}{1+x^2}\,dxarctan⁥x+C\arctan x + C
âˆĢtan⁥x dx\int \tan x\,dxlnâĄâˆŖsec⁥xâˆŖ+C\ln|\sec x| + CRewrite as âˆĢsin⁥xcos⁥x dx\int \frac{\sin x}{\cos x}\,dx
âˆĢsec⁥x dx\int \sec x\,dxlnâĄâˆŖsec⁥x+tan⁥xâˆŖ+C\ln|\sec x + \tan x| + C
âˆĢ1x2+a2 dx\int \frac{1}{x^2+a^2}\,dx1aarctan⁥xa+C\frac{1}{a}\arctan\frac{x}{a} + C
âˆĢ1a2−x2 dx\int \frac{1}{\sqrt{a^2-x^2}}\,dxarcsin⁥xa+C\arcsin\frac{x}{a} + C
âˆĢ1x2−a2 dx\int \frac{1}{x^2-a^2}\,dx12alnâĄâˆŖx−ax+aâˆŖ+C\frac{1}{2a}\ln\left|\frac{x-a}{x+a}\right| + CPartial fractions
âˆĢ1x2Âąa2 dx\int \frac{1}{\sqrt{x^2 \pm a^2}}\,dxlnâĄâˆŖx+x2Âąa2âˆŖ+C\ln|x + \sqrt{x^2 \pm a^2}| + C
âˆĢsinh⁥x dx\int \sinh x\,dxcosh⁥x+C\cosh x + C
âˆĢcosh⁥x dx\int \cosh x\,dxsinh⁥x+C\sinh x + C
âˆĢsech2x dx\int \text{sech}^2 x\,dxtanh⁥x+C\tanh x + C
âˆĢcsch2x dx\int \text{csch}^2 x\,dx−coth x+C-\text{coth } x + C

Improper Integrals

DfImproper Integral

An improper integral is an integral where either the interval of integration is infinite or the integrand has an infinite discontinuity (vertical asymptote) within the interval. We evaluate it as a limit.

Infinite Upper Limit

âˆĢa∞f(x) dx=lim⁥b→∞âˆĢabf(x) dx\int_a^\infty f(x)\,dx = \lim_{b \to \infty} \int_a^b f(x)\,dx

Here,

  • aa=The finite lower bound
  • b→∞b \to \infty=The upper bound approaches infinity

Infinite Lower Limit

âˆĢ−∞bf(x) dx=lim⁥a→−∞âˆĢabf(x) dx\int_{-\infty}^b f(x)\,dx = \lim_{a \to -\infty} \int_a^b f(x)\,dx

Here,

  • a→−∞a \to -\infty=The lower bound approaches negative infinity
  • bb=The finite upper bound

Double Infinite

âˆĢ−∞∞f(x) dx=âˆĢ−∞cf(x) dx+âˆĢc∞f(x) dx\int_{-\infty}^{\infty} f(x)\,dx = \int_{-\infty}^{c} f(x)\,dx + \int_{c}^{\infty} f(x)\,dx

Here,

  • cc=Any finite point (often 0)

DfConvergence and Divergence

An improper integral converges if the limit exists and is finite. It diverges if the limit does not exist or is infinite. Both parts must converge independently for the full integral to converge.

📝Improper Integral That Converges

Problem: Evaluate âˆĢ1∞1x2 dx\int_1^\infty \frac{1}{x^2}\,dx.

💡Solution

âˆĢ1∞1x2 dx=lim⁥b→∞âˆĢ1bx−2 dx=lim⁥b→∞[−1x]1b=lim⁥b→∞(−1b+1)=1\int_1^\infty \frac{1}{x^2}\,dx = \lim_{b \to \infty} \int_1^b x^{-2}\,dx = \lim_{b \to \infty} \left[-\frac{1}{x}\right]_1^b = \lim_{b \to \infty}\left(-\frac{1}{b} + 1\right) = 1.

The integral converges to 11.

📝Improper Integral That Diverges

Problem: Evaluate âˆĢ1∞1x dx\int_1^\infty \frac{1}{x}\,dx.

💡Solution

âˆĢ1∞1x dx=lim⁥b→∞âˆĢ1b1x dx=lim⁥b→∞[ln⁥x]1b=lim⁥b→∞ln⁥b=∞\int_1^\infty \frac{1}{x}\,dx = \lim_{b \to \infty} \int_1^b \frac{1}{x}\,dx = \lim_{b \to \infty} [\ln x]_1^b = \lim_{b \to \infty} \ln b = \infty.

The integral diverges (grows without bound).

â„šī¸ p-Integral Test

âˆĢ1∞1xp dx\int_1^\infty \frac{1}{x^p}\,dx converges if and only if p>1p > 1. This is a quick way to determine convergence for power-type integrands. For example, âˆĢ1∞1x1.01 dx\int_1^\infty \frac{1}{x^{1.01}}\,dx converges (just barely), while âˆĢ1∞1x0.99 dx\int_1^\infty \frac{1}{x^{0.99}}\,dx diverges.

📝Improper Integral with Discontinuity

Problem: Evaluate âˆĢ011x dx\int_0^1 \frac{1}{\sqrt{x}}\,dx.

💡Solution

The integrand has a vertical asymptote at x=0x = 0.

âˆĢ01x−1/2 dx=lim⁥a→0+âˆĢa1x−1/2 dx=lim⁥a→0+[2x]a1=lim⁥a→0+(2−2a)=2\int_0^1 x^{-1/2}\,dx = \lim_{a \to 0^+} \int_a^1 x^{-1/2}\,dx = \lim_{a \to 0^+} [2\sqrt{x}]_a^1 = \lim_{a \to 0^+}(2 - 2\sqrt{a}) = 2.

The integral converges to 22.


Numerical Integration

When an antiderivative cannot be found in closed form, or when the integrand is defined only by data points, we approximate the integral numerically.

Trapezoidal Rule

DfTrapezoidal Rule

Approximates the area under the curve by dividing the interval into nn subintervals and approximating each strip as a trapezoid. The error is proportional to h2h^2 (second-order method).

Trapezoidal Rule

âˆĢabf(x) dx≈h2[f(x0)+2∑i=1n−1f(xi)+f(xn)]\int_a^b f(x)\,dx \approx \frac{h}{2}\left[f(x_0) + 2\sum_{i=1}^{n-1}f(x_i) + f(x_n)\right]

Here,

  • h=b−anh = \frac{b-a}{n}=Width of each subinterval
  • xi=a+ihx_i = a + ih=The i-th grid point
  • nn=Number of subintervals

Simpson's Rule

DfSimpson's Rule

Approximates the area using parabolic arcs instead of straight lines. Requires an even number of subintervals. The error is proportional to h4h^4 (fourth-order method), making it significantly more accurate than the trapezoidal rule for smooth functions.

Simpson's Rule

âˆĢabf(x) dx≈h3[f(x0)+4∑i oddf(xi)+2∑i evenf(xi)+f(xn)]\int_a^b f(x)\,dx \approx \frac{h}{3}\left[f(x_0) + 4\sum_{i \text{ odd}} f(x_i) + 2\sum_{i \text{ even}} f(x_i) + f(x_n)\right]

Here,

  • h=b−anh = \frac{b-a}{n}=Width of each subinterval (n must be even)
  • xi=a+ihx_i = a + ih=The i-th grid point
  • 4∑i odd4 \sum_{i \text{ odd}}=Weight 4 for odd-indexed points
  • 2∑i even2 \sum_{i \text{ even}}=Weight 2 for even-indexed points (except endpoints)

Gaussian Quadrature

DfGaussian Quadrature

A higher-order numerical integration method that chooses both the nodes and weights optimally. An nn-point Gaussian quadrature rule integrates polynomials of degree 2n−12n - 1 exactly. It is particularly efficient for smooth functions.

MethodOrder of AccuracyBest ForNodes Required
TrapezoidalO(h2)O(h^2)Rough data, quick estimatesUniform grid
Simpson'sO(h4)O(h^4)Smooth functions, moderate precisionUniform grid (even nn)
GaussianO(h2n)O(h^{2n})High-precision integration of smooth functionsOptimally placed nodes
Monte CarloO(1/n)O(1/\sqrt{n})High-dimensional integralsRandom samples

💡 Monte Carlo Integration in High Dimensions

For integrals over high-dimensional spaces (common in Bayesian inference and physics simulations), grid-based methods suffer from the curse of dimensionality — the number of grid points grows exponentially with dimension. Monte Carlo integration converges at rate O(1/n)O(1/\sqrt{n}) regardless of dimension, making it the only practical choice for high-dimensional integrals.


Python Implementation

Basic Integration with scipy.integrate

import numpy as np
from scipy import integrate

# Define the function to integrate
def f(x):
    return x**2 * np.exp(-x)

# Compute the integral from 0 to infinity (improper integral)
result, error = integrate.quad(f, 0, np.inf)
print(f"Integral of x^2 * exp(-x) from 0 to inf:")
print(f"  Result: {result:.6f}")
print(f"  Error estimate: {error:.2e}")
print(f"  Exact (2! = 2): 2.000000")

# Definite integral from 0 to 1
result, error = integrate.quad(lambda x: np.sin(x), 0, np.pi)
print(f"\nIntegral of sin(x) from 0 to pi: {result:.6f} (exact: 2)")

Numerical Methods Comparison

import numpy as np
from scipy import integrate

# Define test function: f(x) = x^2
f = lambda x: x**2
a, b = 0, 1
exact = 1/3

# Trapezoidal rule
for n in [10, 100, 1000]:
    x = np.linspace(a, b, n + 1)
    trap_result = np.trapz(f(x), x)
    print(f"Trapezoidal (n={n:4d}): {trap_result:.8f}  error: {abs(trap_result - exact):.2e}")

print()

# Simpson's rule
for n in [10, 100, 1000]:
    x = np.linspace(a, b, n + 1)
    simp_result = integrate.simpson(f(x), x=x)
    print(f"Simpson's   (n={n:4d}): {simp_result:.8f}  error: {abs(simp_result - exact):.2e}")

print()

# Gaussian quadrature (scipy)
for n in [5, 10, 20]:
    result, error = integrate.fixed_quad(lambda x: x**2, a, b, n=n)
    print(f"Gauss quad  (n={n:4d}): {result:.8f}  error: {abs(result - exact):.2e}")

# scipy.integrate.quad (adaptive)
result, error = integrate.quad(f, a, b)
print(f"\nAdaptive quad:      {result:.8f}  error: {error:.2e}")

Symbolic Integration with SymPy

import sympy as sp

x = sp.Symbol('x')

# Symbolic indefinite integral
f = x**2 * sp.exp(x)
F = sp.integrate(f, x)
print(f"Indefinite integral of x^2 * e^x: {F}")

# Definite integral
result = sp.integrate(x**2, (x, 0, 1))
print(f"Definite integral of x^2 from 0 to 1: {result}")

# Improper integral
result = sp.integrate(sp.exp(-x**2), (x, -sp.oo, sp.oo))
print(f"Integral of e^(-x^2) from -inf to inf: {result}")
print(f"  = sqrt(pi) = {sp.sqrt(sp.pi)}")

# Verify Fundamental Theorem
F = sp.integrate(sp.sin(x), x)
print(f"\nAntiderivative of sin(x): {F}")
print(f"FTC: F(pi) - F(0) = {F.subs(x, sp.pi) - F.subs(x, 0)}")

High-Dimensional Integration (Monte Carlo)

import numpy as np

def monte_carlo_integrate(f, bounds, n_samples=100000):
    """Monte Carlo integration for arbitrary dimensions."""
    dim = len(bounds)
    samples = np.random.uniform(
        low=[b[0] for b in bounds],
        high=[b[1] for b in bounds],
        size=(n_samples, dim)
    )
    values = np.array([f(s) for s in samples])
    volume = np.prod([b[1] - b[0] for b in bounds])
    mean_val = np.mean(values)
    std_err = np.std(values) / np.sqrt(n_samples)
    return mean_val * volume, std_err

# Example: integral of x^2 + y^2 over [0,1] x [0,1]
f = lambda p: p[0]**2 + p[1]**2
result, error = monte_carlo_integrate(f, [(0, 1), (0, 1)])
exact = 2/3  # integral of x^2 + y^2 over [0,1]^2
print(f"Monte Carlo estimate: {result:.6f} +/- {error:.6f}")
print(f"Exact value:          {exact:.6f}")

Applications in AI/ML

Probability Density Functions

â„šī¸ Integration and Probability

The entire foundation of continuous probability rests on integration. A probability density function fX(x)f_X(x) must satisfy âˆĢ−∞∞fX(x) dx=1\int_{-\infty}^{\infty} f_X(x)\,dx = 1 (normalization), and the probability of any event is computed as an integral of the density.

Probability from PDF

P(a≤X≤b)=âˆĢabfX(x) dxP(a \leq X \leq b) = \int_a^b f_X(x)\,dx

Here,

  • fX(x)f_X(x)=The probability density function of the random variable X
  • a,ba, b=The interval bounds
  • P(a≤X≤b)P(a \leq X \leq b)=The probability that X falls in [a, b]

Normalization Condition

âˆĢ−∞∞fX(x) dx=1\int_{-\infty}^{\infty} f_X(x)\,dx = 1

Here,

  • fX(x)f_X(x)=A valid PDF must integrate to 1 over its support

Expected Values and Moments

Expected Value

E[X]=âˆĢ−∞∞x⋅fX(x) dxE[X] = \int_{-\infty}^{\infty} x \cdot f_X(x)\,dx

Here,

  • E[X]E[X]=The expected value (mean) of X
  • x⋅fX(x)x \cdot f_X(x)=Each value weighted by its probability density

Variance

Var(X)=E[(X−Îŧ)2]=âˆĢ−∞∞(x−Îŧ)2fX(x) dx\text{Var}(X) = E[(X - \mu)^2] = \int_{-\infty}^{\infty} (x - \mu)^2 f_X(x)\,dx

Here,

  • Îŧ=E[X]\mu = E[X]=The mean of X
  • (x−Îŧ)2(x - \mu)^2=Squared deviation from the mean

General Moment

E[g(X)]=âˆĢ−∞∞g(x)⋅fX(x) dxE[g(X)] = \int_{-\infty}^{\infty} g(x) \cdot f_X(x)\,dx

Here,

  • g(X)g(X)=Any function of the random variable
  • E[g(X)]E[g(X)]=The expected value of g(X) — a weighted average

Bayesian Inference

â„šī¸ Integrals in Bayesian Methods

Bayesian inference is built on integration. The posterior distribution requires the evidence (marginal likelihood), which is an integral: p(Î¸âˆŖdata)=p(dataâˆŖÎ¸)p(θ)âˆĢp(dataâˆŖÎ¸)p(θ) dθp(\theta | \text{data}) = \frac{p(\text{data} | \theta) p(\theta)}{\int p(\text{data} | \theta) p(\theta)\,d\theta}. This integral is often intractable, which is why methods like MCMC, variational inference, and Laplace approximation exist — they all approximate this integral.

Evidence (Marginal Likelihood)

p(data)=âˆĢp(dataâˆŖÎ¸)⋅p(θ) dθp(\text{data}) = \int p(\text{data} | \theta) \cdot p(\theta)\,d\theta

Here,

  • p(dataâˆŖÎ¸)p(\text{data} | \theta)=The likelihood of the data given parameters
  • p(θ)p(\theta)=The prior distribution over parameters
  • p(data)p(\text{data})=The evidence — obtained by integrating over all parameter values

Common Probability Integrals

DistributionPDFKey Integral
Normal N(Îŧ,΃2)\mathcal{N}(\mu, \sigma^2)1΃2Ī€e−(x−Îŧ)22΃2\frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}âˆĢ−∞∞f(x) dx=1\int_{-\infty}^{\infty} f(x)\,dx = 1
Standard Normal12Ī€e−x2/2\frac{1}{\sqrt{2\pi}}e^{-x^2/2}âˆĢ−∞∞e−x2/22Ī€â€‰dx=1\int_{-\infty}^{\infty} \frac{e^{-x^2/2}}{\sqrt{2\pi}}\,dx = 1
Exponential Exp(Îģ)\text{Exp}(\lambda)Îģe−Îģx\lambda e^{-\lambda x}, xâ‰Ĩ0x \geq 0âˆĢ0∞Îģe−Îģx dx=1\int_0^\infty \lambda e^{-\lambda x}\,dx = 1
Beta Beta(Îą,β)\text{Beta}(\alpha, \beta)xα−1(1−x)β−1B(Îą,β)\frac{x^{\alpha-1}(1-x)^{\beta-1}}{B(\alpha,\beta)}âˆĢ01f(x) dx=1\int_0^1 f(x)\,dx = 1
Gamma Gamma(Îą,β)\text{Gamma}(\alpha, \beta)βιxα−1e−βxΓ(Îą)\frac{\beta^\alpha x^{\alpha-1}e^{-\beta x}}{\Gamma(\alpha)}âˆĢ0∞f(x) dx=1\int_0^\infty f(x)\,dx = 1

Common Mistakes

MistakeIncorrectCorrectExplanation
Forgetting the constant of integrationâˆĢx2 dx=x33\int x^2\,dx = \frac{x^3}{3}âˆĢx2 dx=x33+C\int x^2\,dx = \frac{x^3}{3} + CAlways include +C+ C for indefinite integrals
Wrong sign on trig integralâˆĢsin⁥x dx=cos⁥x+C\int \sin x\,dx = \cos x + CâˆĢsin⁥x dx=−cos⁥x+C\int \sin x\,dx = -\cos x + CThe integral of sine is negative cosine
Power rule on 1/x1/xâˆĢ1x dx=x00+C\int \frac{1}{x}\,dx = \frac{x^0}{0} + CâˆĢ1x dx=lnâĄâˆŖxâˆŖ+C\int \frac{1}{x}\,dx = \ln|x| + CPower rule fails at n=−1n = -1; use lnâĄâˆŖxâˆŖ\ln|x|
Not changing bounds on substitutionEvaluate with old bounds after uu-subUpdate bounds when substitutingIf u=g(x)u = g(x), new bounds are g(a)g(a) and g(b)g(b)
Dropping absolute value in ln⁥\lnâˆĢ1x dx=ln⁥(x)+C\int \frac{1}{x}\,dx = \ln(x) + CâˆĢ1x dx=lnâĄâˆŖxâˆŖ+C\int \frac{1}{x}\,dx = \ln|x| + C1x\frac{1}{x} is defined for x<0x < 0 too
Confusing integration with differentiation rulesTreating integrals like derivativesIntegration follows different rulesE.g., âˆĢsin⁥xcos⁥x dx≠sin⁥x⋅sin⁥x\int \sin x \cos x\,dx \neq \sin x \cdot \sin x
Forgetting boundary term in integration by partsâˆĢu dv=−âˆĢv du\int u\,dv = -\int v\,duâˆĢu dv=uv−âˆĢv du\int u\,dv = uv - \int v\,duThe uvuv term is essential
Divergent improper integralsAssuming âˆĢ1∞1xp dx\int_1^\infty \frac{1}{x^p}\,dx always convergesConverges only for p>1p > 1Check convergence before evaluating
Wrong dudu in substitutionForgetting to include the derivativedu=g′(x) dxdu = g'(x)\,dx not just du=g(x)du = g(x)The differential dudu must include the derivative
Splitting integrals incorrectlyâˆĢ−111x dx=0\int_{-1}^{1} \frac{1}{x}\,dx = 0 (by symmetry)âˆĢ−111x dx\int_{-1}^{1} \frac{1}{x}\,dx divergesThe integrand has a singularity at x=0x = 0

âš ī¸ Double-Check Your Work

After computing an integral, verify by differentiating your answer. If âˆĢf(x) dx=F(x)+C\int f(x)\,dx = F(x) + C, then F′(x)F'(x) should equal f(x)f(x). For definite integrals, check boundary values and sign consistency.


Interview Questions

Q1: State the Fundamental Theorem of Calculus and explain its significance.

💡Answer

The Fundamental Theorem of Calculus has two parts:

Part 1: If F(x)=âˆĢaxf(t) dtF(x) = \int_a^x f(t)\,dt and ff is continuous, then F′(x)=f(x)F'(x) = f(x). This shows differentiation undoes integration.

Part 2: If FF is any antiderivative of ff, then âˆĢabf(x) dx=F(b)−F(a)\int_a^b f(x)\,dx = F(b) - F(a). This allows us to compute definite integrals using antiderivatives.

Significance: It connects the two branches of calculus (differential and integral), transforms the problem of computing areas into evaluating antiderivatives, and provides the theoretical foundation for the entire field.

Q2: When would you use integration by parts vs. substitution?

💡Answer

  • Substitution is used when the integrand contains a composition of functions where the inner function's derivative appears as a factor (reverse of the chain rule). Example: âˆĢ2xcos⁥(x2) dx\int 2x\cos(x^2)\,dx.
  • Integration by parts is used for products of different types of functions (reverse of the product rule). Example: âˆĢxex dx\int x e^x\,dx.
  • A good heuristic: if you see a "inner-derivative" pattern, use substitution. If you see a product of different function types (algebraic × exponential, algebraic × trig, etc.), use by parts. The LIATE rule helps choose uu.

Q3: Why does âˆĢ−∞∞e−x2 dx=Ī€\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}? Why is this important in ML?

💡Answer

This is the Gaussian integral. It cannot be computed by finding an antiderivative (since e−x2e^{-x^2} has no elementary antiderivative). The classic proof squares the integral and converts to polar coordinates:

(âˆĢ−∞∞e−x2 dx)2=âˆĢ−∞∞âˆĢ−∞∞e−(x2+y2) dx dy=âˆĢ02Ī€âˆĢ0∞e−r2r dr dθ=Ī€\left(\int_{-\infty}^{\infty} e^{-x^2}\,dx\right)^2 = \int_{-\infty}^{\infty}\int_{-\infty}^{\infty} e^{-(x^2+y^2)}\,dx\,dy = \int_0^{2\pi}\int_0^{\infty} e^{-r^2} r\,dr\,d\theta = \pi.

Taking the square root gives ΀\sqrt{\pi}.

Importance in ML: This integral is the normalization constant for the Gaussian distribution, the most important distribution in statistics and ML. It ensures âˆĢ−∞∞1΃2Ī€e−(x−Îŧ)2/(2΃2) dx=1\int_{-\infty}^{\infty} \frac{1}{\sigma\sqrt{2\pi}}e^{-(x-\mu)^2/(2\sigma^2)}\,dx = 1, which is required for any valid probability distribution.

Q4: Explain the difference between convergence and divergence for improper integrals. Give an example of each.

💡Answer

An improper integral converges if the limit exists and is finite; it diverges if the limit does not exist or is infinite.

Convergent example: âˆĢ1∞1x2 dx=lim⁥b→∞[−1x]1b=1\int_1^\infty \frac{1}{x^2}\,dx = \lim_{b\to\infty}\left[-\frac{1}{x}\right]_1^b = 1. The area is finite despite the infinite interval.

Divergent example: âˆĢ1∞1x dx=lim⁥b→∞ln⁥b=∞\int_1^\infty \frac{1}{x}\,dx = \lim_{b\to\infty}\ln b = \infty. The area grows without bound.

Key insight: The p-test says âˆĢ1∞1xp dx\int_1^\infty \frac{1}{x^p}\,dx converges iff p>1p > 1. For integrals near a singularity like âˆĢ011xp dx\int_0^1 \frac{1}{x^p}\,dx, it converges iff p<1p < 1.

Q5: How is numerical integration used when analytical solutions are unavailable?

💡Answer

When the antiderivative cannot be expressed in closed form (e.g., e−x2e^{-x^2}, sin⁡xx\frac{\sin x}{x}, or integrands defined only by data), we use numerical methods:

  1. Trapezoidal rule: Approximate area with trapezoids. Simple, O(h2)O(h^2) convergence. Good for rough data.
  2. Simpson's rule: Use parabolic arcs. O(h4)O(h^4) convergence. Better for smooth functions.
  3. Gaussian quadrature: Optimally placed nodes. Integrates degree 2n−12n-1 polynomials exactly with nn points.
  4. Monte Carlo integration: Random sampling. Converges at O(1/n)O(1/\sqrt{n}) but is the only practical method for high-dimensional integrals (critical in Bayesian inference).
  5. Adaptive quadrature: Automatically refines the grid where the integrand is difficult. scipy.integrate.quad uses this.

Q6: What role does integration play in training probabilistic models?

💡Answer

Integration is essential in several aspects of probabilistic model training:

  1. Normalization: Every PDF must integrate to 1. For complex models, this constant is often intractable.
  2. Marginalization: To compute p(x)=âˆĢp(x,θ) dθp(x) = \int p(x, \theta)\,d\theta, we integrate out latent variables.
  3. Evidence computation: p(data)=âˆĢp(dataâˆŖÎ¸)p(θ) dθp(\text{data}) = \int p(\text{data}|\theta)p(\theta)\,d\theta is needed for model comparison and Bayesian model selection.
  4. Expected loss: E[L]=âˆĢL(θ)p(Î¸âˆŖdata) dθ\mathbb{E}[\mathcal{L}] = \int \mathcal{L}(\theta) p(\theta|\text{data})\,d\theta — computing the expected loss over the posterior.
  5. Variational inference: Approximates intractable integrals with tractable ones by minimizing KL divergence.
  6. MCMC: Draws samples from posteriors by constructing Markov chains whose stationary distribution is the target — a way to estimate integrals via sampling.

Q7: Prove that âˆĢ01xn dx=1n+1\int_0^1 x^n\,dx = \frac{1}{n+1} using the definition of the integral.

💡Answer

Using the Riemann sum with a uniform partition into nn subintervals of width Δx=1/n\Delta x = 1/n:

âˆĢ01xn dx=lim⁥n→∞∑i=1n(in)n⋅1n=lim⁥n→∞1nn+1∑i=1nin\int_0^1 x^n\,dx = \lim_{n\to\infty} \sum_{i=1}^{n} \left(\frac{i}{n}\right)^n \cdot \frac{1}{n} = \lim_{n\to\infty} \frac{1}{n^{n+1}} \sum_{i=1}^{n} i^n

Using Faulhaber's formula ∑i=1nin≈nn+1n+1\sum_{i=1}^{n} i^n \approx \frac{n^{n+1}}{n+1} for large nn:

âˆĢ01xn dx=lim⁥n→∞1nn+1⋅nn+1n+1=1n+1\int_0^1 x^n\,dx = \lim_{n\to\infty} \frac{1}{n^{n+1}} \cdot \frac{n^{n+1}}{n+1} = \frac{1}{n+1}

Alternatively, by the Fundamental Theorem: âˆĢ01xn dx=[xn+1n+1]01=1n+1\int_0^1 x^n\,dx = \left[\frac{x^{n+1}}{n+1}\right]_0^1 = \frac{1}{n+1}.


Practice Problems

📝Problem 1: Substitution

Compute âˆĢx1+x2 dx\int x\sqrt{1 + x^2}\,dx.

💡Solution

Let u=1+x2u = 1 + x^2, so du=2x dxdu = 2x\,dx and x dx=du2x\,dx = \frac{du}{2}.

âˆĢu⋅du2=12âˆĢu1/2 du=12⋅u3/23/2+C=(1+x2)3/23+C\int \sqrt{u} \cdot \frac{du}{2} = \frac{1}{2} \int u^{1/2}\,du = \frac{1}{2} \cdot \frac{u^{3/2}}{3/2} + C = \frac{(1+x^2)^{3/2}}{3} + C.

📝Problem 2: Integration by Parts

Compute âˆĢx2ex dx\int x^2 e^x\,dx.

💡Solution

First application: u=x2u = x^2, dv=ex dxdv = e^x\,dx. Then du=2x dxdu = 2x\,dx, v=exv = e^x.

âˆĢx2ex dx=x2ex−2âˆĢxex dx\int x^2 e^x\,dx = x^2 e^x - 2\int xe^x\,dx

Second application: u=xu = x, dv=ex dxdv = e^x\,dx. Then du=dxdu = dx, v=exv = e^x.

âˆĢxex dx=xex−âˆĢex dx=xex−ex\int xe^x\,dx = xe^x - \int e^x\,dx = xe^x - e^x

Combine: x2ex−2(xex−ex)+C=ex(x2−2x+2)+Cx^2 e^x - 2(xe^x - e^x) + C = e^x(x^2 - 2x + 2) + C.

📝Problem 3: Definite Integral with Substitution

Compute âˆĢ01ex1+ex dx\int_0^1 \frac{e^x}{1 + e^x}\,dx.

💡Solution

Let u=1+exu = 1 + e^x, so du=ex dxdu = e^x\,dx.

When x=0x = 0: u=2u = 2. When x=1x = 1: u=1+eu = 1 + e.

âˆĢ21+e1u du=[lnâĄâˆŖuâˆŖ]21+e=ln⁥(1+e)−ln⁥2=ln⁥1+e2\int_2^{1+e} \frac{1}{u}\,du = [\ln|u|]_2^{1+e} = \ln(1+e) - \ln 2 = \ln\frac{1+e}{2}.

📝Problem 4: Improper Integral

Determine whether âˆĢ1∞ln⁥xx2 dx\int_1^\infty \frac{\ln x}{x^2}\,dx converges, and if so, evaluate it.

💡Solution

Use integration by parts: u=ln⁡xu = \ln x, dv=x−2 dxdv = x^{-2}\,dx. Then du=1x dxdu = \frac{1}{x}\,dx, v=−1xv = -\frac{1}{x}.

âˆĢln⁥xx2 dx=−ln⁥xx+âˆĢ1x2 dx=−ln⁥xx−1x\int \frac{\ln x}{x^2}\,dx = -\frac{\ln x}{x} + \int \frac{1}{x^2}\,dx = -\frac{\ln x}{x} - \frac{1}{x}

Evaluate the improper integral:

âˆĢ1∞ln⁥xx2 dx=lim⁥b→∞[−ln⁥xx−1x]1b=lim⁥b→∞(−ln⁥bb−1b+0+1)=0−0+1=1\int_1^\infty \frac{\ln x}{x^2}\,dx = \lim_{b\to\infty}\left[-\frac{\ln x}{x} - \frac{1}{x}\right]_1^b = \lim_{b\to\infty}\left(-\frac{\ln b}{b} - \frac{1}{b} + 0 + 1\right) = 0 - 0 + 1 = 1

The integral converges to 11.

📝Problem 5: Probability Application

Let XX have PDF fX(x)=12eâˆ’âˆŖxâˆŖf_X(x) = \frac{1}{2}e^{-|x|} for x∈Rx \in \mathbb{R} (Laplace distribution). Find E[X]E[X] and Var(X)\text{Var}(X).

💡Solution

Expected value: By symmetry of fX(x)f_X(x) (even function) and x⋅fX(x)x \cdot f_X(x) (odd function):

E[X]=âˆĢ−∞∞x⋅12eâˆ’âˆŖxâˆŖâ€‰dx=0E[X] = \int_{-\infty}^{\infty} x \cdot \frac{1}{2}e^{-|x|}\,dx = 0 (odd integrand over symmetric interval).

Variance: Var(X)=E[X2]−(E[X])2=E[X2]\text{Var}(X) = E[X^2] - (E[X])^2 = E[X^2]

E[X2]=âˆĢ−∞∞x2⋅12eâˆ’âˆŖxâˆŖâ€‰dx=2âˆĢ0∞x2⋅12e−x dx=âˆĢ0∞x2e−x dxE[X^2] = \int_{-\infty}^{\infty} x^2 \cdot \frac{1}{2}e^{-|x|}\,dx = 2\int_0^{\infty} x^2 \cdot \frac{1}{2}e^{-x}\,dx = \int_0^{\infty} x^2 e^{-x}\,dx

Using integration by parts twice (or the gamma function Γ(3)=2!=2\Gamma(3) = 2! = 2):

Var(X)=2\text{Var}(X) = 2.


Quick Reference

📋Key Takeaways

  • Indefinite Integral: âˆĢf(x) dx=F(x)+C\int f(x)\,dx = F(x) + C where F′(x)=f(x)F'(x) = f(x) — a family of antiderivatives.
  • Definite Integral: âˆĢabf(x) dx=F(b)−F(a)\int_a^b f(x)\,dx = F(b) - F(a) — the signed area under the curve, computed via the Fundamental Theorem.
  • Fundamental Theorem: Connects differentiation and integration: ddxâˆĢaxf(t) dt=f(x)\frac{d}{dx}\int_a^x f(t)\,dt = f(x) and âˆĢabf(x) dx=F(b)−F(a)\int_a^b f(x)\,dx = F(b) - F(a).
  • Power Rule: âˆĢxn dx=xn+1n+1+C\int x^n\,dx = \frac{x^{n+1}}{n+1} + C for n≠−1n \neq -1; for n=−1n = -1: âˆĢ1x dx=lnâĄâˆŖxâˆŖ+C\int \frac{1}{x}\,dx = \ln|x| + C.
  • Substitution: âˆĢf(g(x))g′(x) dx=âˆĢf(u) du\int f(g(x))g'(x)\,dx = \int f(u)\,du — reverse of the chain rule.
  • Integration by Parts: âˆĢu dv=uv−âˆĢv du\int u\,dv = uv - \int v\,du — reverse of the product rule; use LIATE to choose uu.
  • Improper Integrals: Evaluate as limits; converges if the limit is finite, diverges otherwise.
  • Numerical Methods: Trapezoidal (O(h2)O(h^2)), Simpson's (O(h4)O(h^4)), Gaussian quadrature (O(h2n)O(h^{2n})), Monte Carlo (O(1/n)O(1/\sqrt{n})).
  • Probability: P(a≤X≤b)=âˆĢabfX(x) dxP(a \leq X \leq b) = \int_a^b f_X(x)\,dx, E[X]=âˆĢxfX(x) dxE[X] = \int x f_X(x)\,dx, normalization requires âˆĢfX(x) dx=1\int f_X(x)\,dx = 1.
  • Bayesian Integration: Evidence p(data)=âˆĢp(dataâˆŖÎ¸)p(θ) dθp(\text{data}) = \int p(\text{data}|\theta)p(\theta)\,d\theta is often intractable, motivating MCMC and variational methods.

Cross-References

Lesson Progress28 / 100