Lesson 4 of 18

Improper Integrals

Improper Integrals

An integral with an infinite limit is defined as a limit:

intainftyf(x),dx=limToinftyintaTf(x),dxint_a^{infty} f(x) , dx = lim_{T o infty} int_a^T f(x) , dx

If the limit exists, the integral converges. Otherwise, it diverges.

Key Examples

IntegralResultConverges?
int_1^{infty} rac{1}{x} , dxinftyinftyNo
int_1^{infty} rac{1}{x^2} , dx11Yes
int_1^{infty} rac{1}{x^p} , dx rac{1}{p-1}Yes if p>1p > 1

The p-Test

int_1^{infty} rac{1}{x^p} , dx converges if and only if p>1p > 1.

This is why the harmonic series sum rac{1}{n} diverges (p=1p=1), but sum rac{1}{n^2} converges (p=2p=2).

Numerical Approach

Integrate to a large finite TT:

intainftyf(x),dxapproxintaTf(x),dxquad(Textlarge)int_a^{infty} f(x) , dx approx int_a^T f(x) , dx quad (T ext{ large})

The truncation error is roughly leftintTinftyf(x),dxightleft|int_T^{infty} f(x) , dx ight|. For rac{1}{x^2}, this is rac{1}{T}, so T=100000T=100000 gives 5-decimal accuracy.

Your Task

Implement double improper_integral(double (*f)(double), double a, double T, int n) that approximates intaTf(x),dxint_a^T f(x) , dx using the midpoint rule.

TCC compiler loading...
Loading...
Click "Run" to execute your code.