Chapter 9
20 min read
Section 83 of 353

Integration by Parts

The Indefinite Integral and Antiderivatives

Learning Objectives

By the end of this section, you will be able to:

  1. Understand how integration by parts arises from reversing the product rule for derivatives
  2. Apply the integration by parts formula udv=uvvdu\int u \, dv = uv - \int v \, du to evaluate integrals
  3. Use the LIATE rule to strategically choose uu and dvdv
  4. Master the tabular method for repeated integration by parts
  5. Apply integration by parts to definite integrals with proper boundary evaluation
  6. Connect this technique to physics, probability, signal processing, and machine learning

The Big Picture: Reversing the Product Rule

"Integration by parts is the antiderivative analog of the product rule — it transforms difficult products into manageable pieces."

In differential calculus, the product rule tells us how to differentiate a product of two functions:

ddx[u(x)v(x)]=u(x)v(x)+u(x)v(x)\frac{d}{dx}[u(x) \cdot v(x)] = u'(x) \cdot v(x) + u(x) \cdot v'(x)

But what if we need to go backwards? What if we have an integral of a product and want to find its antiderivative? This is where integration by parts comes in — it's the reverse of the product rule.

The Core Insight

Integration by parts transforms udv\int u \, dv into uvvduuv - \int v \, du. The hope is that vdu\int v \, du is easier to evaluate than the original integral. This technique works when one part of the product simplifies upon differentiation while the other remains manageable upon integration.

Why Do We Need This?

Consider xexdx\int x e^x \, dx. Neither u-substitution nor any basic formula helps here. The product of xx and exe^x doesn't fit any pattern we know — but integration by parts transforms this into something solvable.

Integration by parts is essential for integrals involving:

  • Products of polynomials with exponentials: xnexdx\int x^n e^x \, dx
  • Products of polynomials with trigonometric functions: xsinxdx\int x \sin x \, dx
  • Logarithmic functions: lnxdx\int \ln x \, dx
  • Inverse trigonometric functions: arctanxdx\int \arctan x \, dx
  • Products of trigonometric functions: exsinxdx\int e^x \sin x \, dx

Historical Context

Integration by parts was developed alongside the foundational work of calculus in the 17th century.

Gottfried Wilhelm Leibniz (1646–1716)

Leibniz, who independently developed calculus alongside Newton, recognized that his product rule for differentiation could be "inverted" to create a technique for integration. His notation udv\int u \, dv emphasizes the differential form, making the relationship between differentiation and integration explicit.

Leibniz's insight was profound: since d(uv)=udv+vdud(uv) = u \, dv + v \, du, we can rearrange to get udv=d(uv)vduu \, dv = d(uv) - v \, du. Integrating both sides gives the integration by parts formula.

The Name "Integration by Parts"

The name comes from the idea that we split the integrand into two "parts": one part (uu) that we differentiate, and another part (dvdv) that we integrate. The technique redistributes the complexity between these parts, hopefully making the integral easier.


Derivation from the Product Rule

Let's derive the integration by parts formula step by step from the product rule.

Step 1: Start with the Product Rule

For two differentiable functions u(x)u(x) and v(x)v(x):

ddx[u(x)v(x)]=u(x)v(x)+u(x)v(x)\frac{d}{dx}[u(x) v(x)] = u'(x) v(x) + u(x) v'(x)

Step 2: Rearrange

Isolate one of the product terms:

u(x)v(x)=ddx[u(x)v(x)]u(x)v(x)u(x) v'(x) = \frac{d}{dx}[u(x) v(x)] - u'(x) v(x)

Step 3: Integrate Both Sides

Integrate with respect to xx:

u(x)v(x)dx=u(x)v(x)u(x)v(x)dx\int u(x) v'(x) \, dx = u(x) v(x) - \int u'(x) v(x) \, dx

The left side integrates the derivative ddx[uv]\frac{d}{dx}[uv], which simply gives uvuv.

Step 4: Write in Differential Form

Using Leibniz notation where du=u(x)dxdu = u'(x) \, dx and dv=v(x)dxdv = v'(x) \, dx:

Integration by Parts Formula

udv=uvvdu\int u \, dv = uv - \int v \, du

Where uu and vv are functions of xx

Memory Aid

Think of it as: "Ultra-Violet minus Voodoo" uvvduuv - \int v \, du. The integral "trades" one problem for another: we lose the dvdv but gain dudu.


The Integration by Parts Formula

The Process

To evaluate f(x)g(x)dx\int f(x) g(x) \, dx using integration by parts:

  1. Choose which factor to call uu and which to call dvdv
  2. Differentiate uu to find dudu
  3. Integrate dvdv to find vv
  4. Apply the formula: udv=uvvdu\int u \, dv = uv - \int v \, du
  5. Evaluate the new integral vdu\int v \, du

A First Example: xexdx\int x e^x \, dx

Step 1: Identify u and dv

Let u=xu = x and dv=exdxdv = e^x \, dx

Step 2: Find du and v

  • du=dxdu = dx
  • v=exdx=exv = \int e^x \, dx = e^x

Step 3: Apply the Formula

xexdx=xexexdx\int x e^x \, dx = x e^x - \int e^x \, dx

Step 4: Evaluate the Remaining Integral

xexdx=xexex+C=ex(x1)+C\int x e^x \, dx = x e^x - e^x + C = e^x(x - 1) + C

Verification

We can verify by differentiating: ddx[ex(x1)]=ex(x1)+ex=xex\frac{d}{dx}[e^x(x-1)] = e^x(x-1) + e^x = xe^x

Interactive: Visualizing Integration by Parts

Explore how integration by parts works geometrically. See how the choice of uu and dvdv transforms the integral:

Integration by Parts Step-by-Step

1. Identify the Integral2. Choose u and dv3. Compute du and v4. Apply the Formula5. Evaluate ∫v du6. Final Answer

We want to evaluate:

x e^x dx

This is a product of two functions. We'll use integration by parts.

Remember: ∫ u dv = uv − ∫ v du

Choosing u and dv: The LIATE Rule

The success of integration by parts depends critically on choosing uu and dvdv wisely. The LIATE rule is a heuristic that suggests which function to choose as uu.

The LIATE Rule

Choose uu to be the function that appears earliest in this list:

L
Logarithmic
lnx\ln x
I
Inverse Trig
arctanx\arctan x
A
Algebraic
xnx^n
T
Trigonometric
sinx\sin x
E
Exponential
exe^x

Why LIATE Works

Functions earlier in the list generally become simpler when differentiated:

  • lnx1x\ln x \to \frac{1}{x} — logarithms become algebraic
  • arctanx11+x2\arctan x \to \frac{1}{1+x^2} — inverse trig becomes rational
  • xnnxn1x^n \to nx^{n-1} — polynomials reduce degree
  • sinxcosx\sin x \to \cos x — trig stays trig
  • exexe^x \to e^x — exponentials stay the same

Meanwhile, functions later in the list are easy to integrate:

  • exdx=ex\int e^x \, dx = e^x
  • sinxdx=cosx\int \sin x \, dx = -\cos x
  • xndx=xn+1n+1\int x^n \, dx = \frac{x^{n+1}}{n+1}
Integralu (using LIATE)dvReason
∫ x·eˣ dxx (Algebraic)eˣ dxA comes before E; differentiating x simplifies it
∫ x·sin(x) dxx (Algebraic)sin(x) dxA comes before T; x reduces degree
∫ ln(x) dxln(x) (Logarithmic)dxL is first; ln(x) becomes 1/x
∫ x²·ln(x) dxln(x) (Logarithmic)x² dxL comes before A
∫ arctan(x) dxarctan(x) (Inverse)dxI is second; becomes rational
∫ eˣ·sin(x) dxEither works!Either works!Special case: requires two IBP cycles

LIATE is a Guideline, Not a Law

The LIATE rule works for most integrals, but there are exceptions. If your first choice leads to a more complicated integral, try the other option. Experience helps develop intuition for when to deviate.


Worked Examples

Example 1: x2exdx\int x^2 e^x \, dx

Analysis: By LIATE, u=x2u = x^2 (Algebraic) and dv=exdxdv = e^x \, dx (Exponential).

First Application:

  • u=x2u = x^2, du=2xdxdu = 2x \, dx
  • dv=exdxdv = e^x \, dx, v=exv = e^x
x2exdx=x2ex2xexdx=x2ex2xexdx\int x^2 e^x \, dx = x^2 e^x - \int 2x e^x \, dx = x^2 e^x - 2 \int x e^x \, dx

Second Application on xexdx\int x e^x \, dx:

  • u=xu = x, du=dxdu = dx
  • dv=exdxdv = e^x \, dx, v=exv = e^x
xexdx=xexex\int x e^x \, dx = x e^x - e^x

Final Result:

x2exdx=x2ex2(xexex)+C=ex(x22x+2)+C\int x^2 e^x \, dx = x^2 e^x - 2(x e^x - e^x) + C = e^x(x^2 - 2x + 2) + C

Example 2: lnxdx\int \ln x \, dx

Key Insight: We write this as 1lnxdx\int 1 \cdot \ln x \, dx and choose u=lnxu = \ln x, dv=dxdv = dx.

  • u=lnxu = \ln x, du=1xdxdu = \frac{1}{x} \, dx
  • dv=dxdv = dx, v=xv = x
lnxdx=xlnxx1xdx=xlnx1dx\int \ln x \, dx = x \ln x - \int x \cdot \frac{1}{x} \, dx = x \ln x - \int 1 \, dx
lnxdx=xlnxx+C=x(lnx1)+C\int \ln x \, dx = x \ln x - x + C = x(\ln x - 1) + C

Example 3: exsinxdx\int e^x \sin x \, dx (The Cycling Case)

Special Situation: Both functions are at the same "level" in LIATE. We'll need to apply IBP twice and solve for the original integral.

First Application: Let u=exu = e^x, dv=sinxdxdv = \sin x \, dx

  • du=exdxdu = e^x \, dx, v=cosxv = -\cos x
exsinxdx=excosx+excosxdx\int e^x \sin x \, dx = -e^x \cos x + \int e^x \cos x \, dx

Second Application on excosxdx\int e^x \cos x \, dx: Let u=exu = e^x, dv=cosxdxdv = \cos x \, dx

excosxdx=exsinxexsinxdx\int e^x \cos x \, dx = e^x \sin x - \int e^x \sin x \, dx

Substitute Back:

exsinxdx=excosx+exsinxexsinxdx\int e^x \sin x \, dx = -e^x \cos x + e^x \sin x - \int e^x \sin x \, dx

Solve for the Integral: Let I=exsinxdxI = \int e^x \sin x \, dx

I=excosx+exsinxI    2I=ex(sinxcosx)I = -e^x \cos x + e^x \sin x - I \implies 2I = e^x(\sin x - \cos x)
exsinxdx=ex(sinxcosx)2+C\int e^x \sin x \, dx = \frac{e^x(\sin x - \cos x)}{2} + C

Example 4: arctanxdx\int \arctan x \, dx

Setup: Write as 1arctanxdx\int 1 \cdot \arctan x \, dx with u=arctanxu = \arctan x, dv=dxdv = dx.

  • u=arctanxu = \arctan x, du=11+x2dxdu = \frac{1}{1+x^2} \, dx
  • dv=dxdv = dx, v=xv = x
arctanxdx=xarctanxx1+x2dx\int \arctan x \, dx = x \arctan x - \int \frac{x}{1+x^2} \, dx

The remaining integral uses u-substitution with w=1+x2w = 1 + x^2:

arctanxdx=xarctanx12ln(1+x2)+C\int \arctan x \, dx = x \arctan x - \frac{1}{2} \ln(1 + x^2) + C

Tabular Integration Method

When you need to apply integration by parts multiple times — especially when the uu factor is a polynomial that eventually differentiates to zero — the tabular method (also called the tic-tac-toe method) provides an efficient shortcut.

The Process

  1. Create two columns: one for successive derivatives of uu, one for successive integrals of dvdv
  2. Continue until the uu column reaches zero (for polynomials) or a pattern emerges
  3. Draw diagonal lines connecting entries
  4. Alternate signs: +,,+,,+, -, +, -, \ldots
  5. Multiply along each diagonal and sum

Example: x3e2xdx\int x^3 e^{2x} \, dx

Signu and derivativesdv and integrals
+e^(2x)
-3x²(1/2)e^(2x)
+6x(1/4)e^(2x)
-6(1/8)e^(2x)
+0(1/16)e^(2x)

Result: Multiply diagonally and sum:

x3e2xdx=e2x2(x33x22+6x468)+C\int x^3 e^{2x} \, dx = \frac{e^{2x}}{2}\left(x^3 - \frac{3x^2}{2} + \frac{6x}{4} - \frac{6}{8}\right) + C
=e2x8(4x36x2+6x3)+C= \frac{e^{2x}}{8}(4x^3 - 6x^2 + 6x - 3) + C

Interactive: Tabular Method

Practice the tabular method interactively. See how the table builds and how the alternating signs combine with diagonal products:

Tabular Integration Method

Building table for: x² eˣ dx with u = , dv = dx
SignDerivatives of uIntegrals of dv
+
↓ differentiate
↓ integrate
How it works: Multiply diagonally (each u-row with the v-row below it), alternating signs (+, −, +, −, ...), and sum. Stop when u reaches 0.

Repeated Integration by Parts

Some integrals require applying integration by parts multiple times. There are two common scenarios:

Case 1: Polynomial Reduction

When uu is a polynomial of degree nn, you need nn applications of IBP. Each application reduces the degree by 1, until the polynomial becomes a constant.

Examples:

  • x2sinxdx\int x^2 \sin x \, dx — needs 2 applications
  • x4exdx\int x^4 e^x \, dx — needs 4 applications

Case 2: Cyclic Return

When both factors regenerate (like exsinxe^x \sin x), the original integral appears again after 2 applications. Solve algebraically:

If I=exsinxdxI = \int e^x \sin x \, dx and after two IBP applications we get:

I=exsinxexcosxII = e^x \sin x - e^x \cos x - I

Then:

2I=ex(sinxcosx)    I=ex(sinxcosx)22I = e^x(\sin x - \cos x) \implies I = \frac{e^x(\sin x - \cos x)}{2}

Integration by Parts for Definite Integrals

For definite integrals, we evaluate the boundary terms [uv]ab[uv]_a^b at the limits:

Integration by Parts for Definite Integrals

abudv=[uv]ababvdu\int_a^b u \, dv = [uv]_a^b - \int_a^b v \, du

Where [uv]ab=u(b)v(b)u(a)v(a)[uv]_a^b = u(b)v(b) - u(a)v(a)

Example: 01xexdx\int_0^1 x e^x \, dx

With u=xu = x, dv=exdxdv = e^x \, dx:

01xexdx=[xex]0101exdx\int_0^1 x e^x \, dx = [x e^x]_0^1 - \int_0^1 e^x \, dx

Evaluate:

=(1e10e0)[ex]01=e(e1)=1= (1 \cdot e^1 - 0 \cdot e^0) - [e^x]_0^1 = e - (e - 1) = 1
01xexdx=1\int_0^1 x e^x \, dx = 1

Real-World Applications

Integration by parts appears throughout science and engineering whenever we need to integrate products of functions.

Physics: Work Done by Variable Forces

When both force and displacement are time-dependent, the work integral often requires IBP:

W=0TF(t)v(t)dtW = \int_0^T F(t) \cdot v(t) \, dt

Example: A motor starting up with F(t)=F0tF(t) = F_0 t and v(t)=v0ektv(t) = v_0 e^{-kt}

Probability: Expected Values

Computing expected values of continuous distributions invariably involves products:

E[X]=0xf(x)dxE[X] = \int_0^\infty x \cdot f(x) \, dx

For the exponential distribution: E[X]=0xλeλxdx=1λE[X] = \int_0^\infty x \lambda e^{-\lambda x} \, dx = \frac{1}{\lambda}

Signal Processing: Fourier Coefficients

Computing Fourier coefficients for non-sinusoidal waves:

bn=2L0Lf(x)sin(nπxL)dxb_n = \frac{2}{L} \int_0^L f(x) \sin\left(\frac{n\pi x}{L}\right) dx

When f(x)f(x) is polynomial or exponential, IBP is needed.

Control Systems: Laplace Transforms

The property L{tf(t)}=ddsF(s)\mathcal{L}\{t f(t)\} = -\frac{d}{ds} F(s) is derived using integration by parts:

L{f(t)}=0f(t)estdt\mathcal{L}\{f(t)\} = \int_0^\infty f(t) e^{-st} \, dt

Differentiating with respect to ss brings down a factor of t-t, creating an IBP situation.


Machine Learning Connection

Integration by parts plays a subtle but important role in machine learning and statistics.

The Score Function and REINFORCE

In reinforcement learning, we often need to compute gradients of expectations:

θExpθ[f(x)]=θf(x)p(xθ)dx\nabla_\theta \mathbb{E}_{x \sim p_\theta}[f(x)] = \nabla_\theta \int f(x) p(x|\theta) \, dx

The key insight (derived using integration by parts) is that this equals:

=Expθ[f(x)θlogp(xθ)]= \mathbb{E}_{x \sim p_\theta}[f(x) \nabla_\theta \log p(x|\theta)]

This is the score function estimator (or REINFORCE trick). The transformation uses integration by parts:

θp(xθ)=p(xθ)θlogp(xθ)\nabla_\theta p(x|\theta) = p(x|\theta) \nabla_\theta \log p(x|\theta)

Since logp=pp\nabla \log p = \frac{\nabla p}{p}

The Gamma Function Recurrence

The Gamma function Γ(n)=0xn1exdx\Gamma(n) = \int_0^\infty x^{n-1} e^{-x} \, dx satisfies Γ(n+1)=nΓ(n)\Gamma(n+1) = n \cdot \Gamma(n), proven by integration by parts. This is fundamental for:

  • Gamma distribution normalization
  • Chi-squared distribution
  • Student's t-distribution
  • Beta function and Bayesian inference

Variance Reduction in Monte Carlo

The control variate method in variance reduction uses integration by parts to derive optimal baseline functions that reduce the variance of gradient estimators in policy gradient methods.


Python Implementation

Numerical and Symbolic Integration by Parts

Here's how to verify integration by parts numerically and perform it symbolically:

Integration by Parts: Numerical and Symbolic
🐍integration_by_parts.py
10Setting Up the IBP

We identify u = x and dv = e^x dx. This choice follows the LIATE rule: x is algebraic, e^x is exponential. The algebraic term simplifies when differentiated.

18Numerical Integration

SciPy's quad function uses adaptive quadrature to compute the definite integral. This serves as ground truth to verify our analytical solution.

22Analytical Solution

After applying IBP: ∫xe^x dx = xe^x - ∫e^x dx = xe^x - e^x = (x-1)e^x. Evaluating from 0 to 1 gives [(1-1)e - (0-1)1] = 0 - (-1) = 1.

45Symbolic Integration

SymPy automatically applies integration by parts (and other techniques) to find antiderivatives. This shows the power of computer algebra systems.

67Score Function Gradient

The REINFORCE trick in reinforcement learning uses integration by parts to express gradients of expectations as expectations of gradients - enabling gradient estimation via sampling.

94Gamma Function Recurrence

The fundamental property Γ(n+1) = n·Γ(n) is proven using integration by parts. This connects calculus to probability theory (Gamma, Chi-squared distributions).

137 lines without explanation
1import numpy as np
2from scipy import integrate
3import sympy as sp
4
5def integration_by_parts_numerical():
6    """
7    Verify integration by parts numerically:
8    ∫ u dv = uv - ∫ v du
9
10    Example: ∫ x·e^x dx from 0 to 1
11    Let u = x, dv = e^x dx
12    Then du = dx, v = e^x
13
14    ∫ x·e^x dx = x·e^x - ∫ e^x dx = x·e^x - e^x + C = (x-1)e^x + C
15    """
16    # Define the integrand f(x) = x * e^x
17    def f(x):
18        return x * np.exp(x)
19
20    # Numerical integration using scipy
21    numerical_result, error = integrate.quad(f, 0, 1)
22
23    # Analytical result: [(x-1)e^x] from 0 to 1
24    # At x=1: (1-1)e^1 = 0
25    # At x=0: (0-1)e^0 = -1
26    # Result: 0 - (-1) = 1
27    analytical_result = 1.0
28
29    print("Integration by Parts: ∫₀¹ x·eˣ dx")
30    print("=" * 45)
31    print(f"Numerical result:  {numerical_result:.10f}")
32    print(f"Analytical result: {analytical_result:.10f}")
33    print(f"Absolute error:    {abs(numerical_result - analytical_result):.2e}")
34
35    return numerical_result, analytical_result
36
37def integration_by_parts_symbolic():
38    """
39    Use SymPy to perform integration by parts symbolically.
40    This demonstrates how computer algebra systems apply IBP.
41    """
42    x = sp.Symbol('x')
43
44    # Define examples that require integration by parts
45    examples = [
46        ("x * exp(x)", x * sp.exp(x)),
47        ("x * sin(x)", x * sp.sin(x)),
48        ("x^2 * cos(x)", x**2 * sp.cos(x)),
49        ("ln(x)", sp.ln(x)),
50        ("x * ln(x)", x * sp.ln(x)),
51        ("arctan(x)", sp.atan(x)),
52    ]
53
54    print("\nSymbolic Integration by Parts Examples")
55    print("=" * 55)
56
57    for name, expr in examples:
58        result = sp.integrate(expr, x)
59        result_simplified = sp.simplify(result)
60        print(f"\n∫ {name} dx = {result_simplified}")
61
62    return examples
63
64def ibp_ml_application():
65    """
66    Integration by parts in Machine Learning:
67    Computing expectations and gradients of log-probability.
68
69    In reinforcement learning, the score function gradient:
70    ∇_θ E[f(x)] = E[f(x) ∇_θ log p(x|θ)]
71
72    This derivation uses integration by parts!
73    """
74    print("\n" + "=" * 55)
75    print("Integration by Parts in Machine Learning")
76    print("=" * 55)
77
78    # Demonstrate with Gaussian distribution
79    # For Gaussian: p(x|μ,σ) = (1/√(2πσ²)) exp(-(x-μ)²/(2σ²))
80    # Score function: ∇_μ log p(x|μ,σ) = (x-μ)/σ²
81
82    mu, sigma = 0.0, 1.0
83    n_samples = 100000
84
85    # Sample from Gaussian
86    samples = np.random.normal(mu, sigma, n_samples)
87
88    # For any function f(x), we can estimate:
89    # ∇_μ E[f(x)] ≈ (1/N) Σ f(xᵢ) · (xᵢ - μ)/σ²
90
91    # Example: f(x) = x² (so E[f(x)] = μ² + σ² = 1)
92    f_samples = samples ** 2
93    score_values = (samples - mu) / (sigma ** 2)
94
95    # Score function gradient estimate
96    gradient_estimate = np.mean(f_samples * score_values)
97
98    # True gradient: ∂/∂μ (μ² + σ²) = 2μ = 0
99    true_gradient = 2 * mu
100
101    print(f"\nScore Function Gradient (REINFORCE trick)")
102    print(f"Function: f(x) = x²")
103    print(f"True gradient ∂/∂μ E[x²]:  {true_gradient:.6f}")
104    print(f"Estimated gradient:        {gradient_estimate:.6f}")
105    print(f"\nThis technique is derived using integration by parts!")
106    print("∇_θ E[f(x)] = ∫ f(x) ∇_θ p(x|θ) dx")
107    print("            = ∫ f(x) p(x|θ) ∇_θ log p(x|θ) dx")
108    print("            = E[f(x) ∇_θ log p(x|θ)]")
109
110def gamma_function_ibp():
111    """
112    The Gamma function Γ(n) = ∫₀^∞ x^(n-1) e^(-x) dx
113    satisfies Γ(n+1) = n·Γ(n), proven by integration by parts!
114
115    This property is fundamental in probability distributions
116    (Gamma, Chi-squared, Student-t, etc.)
117    """
118    print("\n" + "=" * 55)
119    print("Integration by Parts and the Gamma Function")
120    print("=" * 55)
121
122    from scipy.special import gamma
123
124    # Verify Γ(n+1) = n·Γ(n) for several values
125    print("\nVerifying Γ(n+1) = n·Γ(n):")
126    print("-" * 40)
127
128    for n in [1, 2, 3, 4, 5, 0.5, 1.5, 2.5]:
129        gamma_n = gamma(n)
130        gamma_n_plus_1 = gamma(n + 1)
131        ratio = gamma_n_plus_1 / gamma_n
132
133        print(f"n = {n:>4}: Γ({n+1}) / Γ({n}) = {ratio:.6f}{n}")
134
135    print("\nThis recurrence is proven by IBP with u=x^(n-1), dv=e^(-x)dx")
136    print("Γ(n+1) = ∫₀^∞ xⁿ e^(-x) dx = [-xⁿe^(-x)]₀^∞ + n∫₀^∞ x^(n-1)e^(-x) dx")
137    print("       = 0 + n·Γ(n) = n·Γ(n)")
138
139# Run all demonstrations
140integration_by_parts_numerical()
141integration_by_parts_symbolic()
142ibp_ml_application()
143gamma_function_ibp()

Applications in Physics and Engineering

See how integration by parts applies to real-world problems:

Real-World Applications
🐍ibp_applications.py
11Physics: Variable Force Work

When force and velocity are both functions of time, the work integral often requires IBP. Here F(t) = F₀t and v(t) = v₀e^(-kt) model a motor starting under load.

25Analytical IBP Solution

Integration by parts gives ∫te^(-kt)dt = (-t/k - 1/k²)e^(-kt). The algebraic term t becomes simpler after differentiation, while e^(-kt) integrates cleanly.

44Probability: Expected Value

The expected value E[X] = ∫xf(x)dx always involves products of x with the PDF. For exponential, gamma, and many other distributions, this requires IBP.

71Fourier Coefficients

Fourier series coefficients for non-sinusoidal waves typically require IBP. The integral ∫x·sin(nx)dx appears when computing bₙ for signals with linear trends.

93Laplace Transform Derivative

The property L{t·f(t)} = -dF(s)/ds is fundamental in control systems. It is derived using integration by parts and enables solving differential equations algebraically.

141 lines without explanation
1import numpy as np
2from scipy import integrate
3import matplotlib.pyplot as plt
4
5def physics_work_integral():
6    """
7    Work done by a time-varying force:
8    W = ∫₀^T F(t) · v(t) dt
9
10    When F(t) = F₀·t (linearly increasing force) and
11    v(t) = v₀·e^(-kt) (exponentially decaying velocity),
12    we need integration by parts!
13    """
14    F0, v0, k, T = 10.0, 5.0, 0.5, 4.0
15
16    # Integrand: F(t)·v(t) = F₀·v₀·t·e^(-kt)
17    def integrand(t):
18        return F0 * v0 * t * np.exp(-k * t)
19
20    # Numerical solution
21    work_numerical, _ = integrate.quad(integrand, 0, T)
22
23    # Analytical solution using IBP:
24    # ∫ t·e^(-kt) dt = -t/k · e^(-kt) - 1/k² · e^(-kt)
25    def analytical_antiderivative(t):
26        return (-t/k - 1/k**2) * np.exp(-k * t)
27
28    work_analytical = F0 * v0 * (
29        analytical_antiderivative(T) - analytical_antiderivative(0)
30    )
31
32    print("Physics: Work Done by Time-Varying Force")
33    print("=" * 45)
34    print(f"F(t) = {F0}t N, v(t) = {v0}e^(-{k}t) m/s")
35    print(f"Numerical W = {work_numerical:.4f} J")
36    print(f"Analytical W = {work_analytical:.4f} J")
37
38    return work_numerical
39
40def probability_expectation():
41    """
42    Expected value of X for exponential distribution:
43    E[X] = ∫₀^∞ x · λe^(-λx) dx
44
45    This requires integration by parts!
46    """
47    lambda_param = 2.0
48
49    def integrand(x):
50        return x * lambda_param * np.exp(-lambda_param * x)
51
52    # Numerical integration
53    E_X_numerical, _ = integrate.quad(integrand, 0, np.inf)
54
55    # Analytical: E[X] = 1/λ for exponential distribution
56    E_X_analytical = 1 / lambda_param
57
58    print("\nProbability: Expected Value of Exponential Distribution")
59    print("=" * 55)
60    print(f"E[X] = ∫₀^∞ x · λe^(-λx) dx, with λ = {lambda_param}")
61    print(f"Numerical E[X] = {E_X_numerical:.6f}")
62    print(f"Analytical E[X] = 1/λ = {E_X_analytical:.6f}")
63
64    # Show IBP steps
65    print("\nUsing IBP with u = x, dv = λe^(-λx)dx:")
66    print("du = dx, v = -e^(-λx)")
67    print("∫xλe^(-λx)dx = -xe^(-λx)|₀^∞ + ∫e^(-λx)dx")
68    print("            = 0 + [-1/λ · e^(-λx)]₀^∞ = 1/λ")
69
70    return E_X_numerical
71
72def signal_processing_fourier():
73    """
74    Fourier coefficients often require integration by parts.
75
76    For a sawtooth wave f(x) = x on [0, 2π]:
77    bₙ = (1/π) ∫₀^(2π) x·sin(nx) dx
78
79    This integral requires IBP!
80    """
81    def compute_fourier_coefficient(n):
82        def integrand(x):
83            return x * np.sin(n * x)
84
85        result, _ = integrate.quad(integrand, 0, 2*np.pi)
86        return result / np.pi
87
88    print("\nSignal Processing: Fourier Coefficients of Sawtooth Wave")
89    print("=" * 55)
90    print("f(x) = x on [0, 2π], computing bₙ = (1/π)∫₀^(2π) x·sin(nx) dx")
91    print("-" * 55)
92
93    for n in range(1, 6):
94        bn = compute_fourier_coefficient(n)
95        # Analytical result from IBP: bₙ = -2/n
96        bn_analytical = -2.0 / n
97        print(f"b{n} = {bn:.6f} (analytical: {bn_analytical:.6f})")
98
99    print("\nUsing IBP with u = x, dv = sin(nx)dx:")
100    print("bₙ = (1/π)[−x/n·cos(nx) + 1/n²·sin(nx)]₀^(2π)")
101    print("   = (1/π)(−2π/n) = −2/n")
102
103def control_systems_laplace():
104    """
105    In control systems, integration by parts is used to derive
106    Laplace transforms. The Laplace transform of t·f(t) is:
107
108    L{t·f(t)} = -d/ds F(s)
109
110    This is proven using integration by parts!
111    """
112    print("\nControl Systems: Laplace Transform Property")
113    print("=" * 55)
114    print("L{t·f(t)} = ∫₀^∞ t·f(t)·e^(-st) dt")
115    print("\nUsing IBP on ∫₀^∞ f(t)·e^(-st) dt:")
116    print("  u = e^(-st), dv = f(t)dt")
117    print("  du = -s·e^(-st)dt, v = ∫f(t)dt")
118    print("\nDifferentiating F(s) with respect to s:")
119    print("  d/ds F(s) = d/ds ∫₀^∞ f(t)e^(-st) dt")
120    print("            = ∫₀^∞ f(t)·(-t)·e^(-st) dt")
121    print("            = -L{t·f(t)}")
122    print("\nTherefore: L{t·f(t)} = -d/ds F(s)")
123
124    # Verify with example: f(t) = e^(-at)
125    # F(s) = 1/(s+a)
126    # L{t·e^(-at)} = -d/ds[1/(s+a)] = 1/(s+a)²
127
128    a, s = 2.0, 3.0
129
130    # Numerical verification
131    def integrand(t):
132        return t * np.exp(-a*t) * np.exp(-s*t)
133
134    numerical_result, _ = integrate.quad(integrand, 0, 100)
135    analytical_result = 1 / (s + a)**2
136
137    print(f"\nExample: f(t) = e^(-{a}t), s = {s}")
138    print(f"L{{t·e^(-{a}t)}} at s={s}:")
139    print(f"  Numerical:  {numerical_result:.6f}")
140    print(f"  Analytical: {analytical_result:.6f}")
141
142# Run demonstrations
143physics_work_integral()
144probability_expectation()
145signal_processing_fourier()
146control_systems_laplace()

Common Mistakes to Avoid

Mistake 1: Wrong Choice of u and dv

Wrong: For xexdx\int x e^x \, dx, choosing u=exu = e^x and dv=xdxdv = x \, dx

This gives exx22dx\int e^x \cdot \frac{x^2}{2} \, dx — harder, not easier!

Correct: Use LIATE: u=xu = x, dv=exdxdv = e^x \, dx

Mistake 2: Forgetting the Constant of Integration

When finding vv from dvdv, we don't add +C+C at that step — but we must add it to the final answer.

Mistake 3: Sign Errors in the Tabular Method

The alternating signs are crucial: +,,+,,+, -, +, -, \ldots. A sign error propagates through the entire calculation.

Mistake 4: Not Recognizing the Cycling Case

For exsinxdx\int e^x \sin x \, dx, don't keep applying IBP indefinitely. After 2 applications, the original integral reappears — solve for it algebraically.

Mistake 5: Ignoring Boundary Terms for Definite Integrals

For abudv\int_a^b u \, dv, remember to evaluate [uv]ab[uv]_a^b first before computing the remaining integral.


Test Your Understanding

Question 1 of 8Score: 0/0

For ∫ x cos(x) dx, what should you choose as u according to LIATE?


Summary

Integration by parts is a powerful technique derived from the product rule that transforms difficult integrals into manageable ones.

Key Formulas

FormulaWhen to Use
∫ u dv = uv - ∫ v duBasic integration by parts
∫ₐᵇ u dv = [uv]ₐᵇ - ∫ₐᵇ v duDefinite integrals
LIATE: L-I-A-T-EChoosing u (Log, Inverse trig, Algebraic, Trig, Exp)
Tabular methodRepeated IBP with polynomials
Solve for I when I reappearsCycling cases (eˣ sin x, eˣ cos x)

Key Takeaways

  1. IBP reverses the product rule: It transforms udv\int u \, dv into uvvduuv - \int v \, du
  2. LIATE guides your choice: Choose uu to be the function that simplifies upon differentiation
  3. Tabular method saves time: For polynomials times exponentials/trig, build a table
  4. Watch for cycles: When the original integral reappears, solve algebraically
  5. Verify by differentiation: Always check your answer by differentiating
  6. Applications abound: From physics to probability to machine learning, IBP is essential
The Core Insight:
"Integration by parts trades one integral for another — the art is choosing the trade that makes your life easier."
Coming Next: In Trigonometric Integrals, we'll explore specialized techniques for integrating products and powers of trigonometric functions.
Loading comments...