Lesson 1 of 18

Numerical Limits

Limits

The limit is the foundation of calculus. Informally, limxaf(x)=L\lim_{x \to a} f(x) = L means: as xx gets arbitrarily close to aa, f(x)f(x) gets arbitrarily close to LL.

Why Limits Matter

Limits let us deal with quantities we can't compute directly — like the slope of a curve at a single point, or the sum of infinitely many terms.

Numerical Approximation

We can approximate a limit numerically by evaluating ff at points very close to aa, approaching from both sides:

limxaf(x)f(ah)+f(a+h)2\lim_{x \to a} f(x) \approx \frac{f(a - h) + f(a + h)}{2}

For a smooth function, this central average is very accurate when hh is small (e.g., h = 1e-7).

Examples

FunctionPointLimit
x2x^2x3x \to 399
x24x2\frac{x^2 - 4}{x - 2}x2x \to 244
sinxx\frac{\sin x}{x}x0x \to 011

The third example is famous: f(0)f(0) is undefined (division by zero), but the limit exists.

Removable Discontinuities

When f(a)f(a) is undefined but the limit exists, the point is called a removable discontinuity. The function x24x2=(x+2)(x2)x2=x+2\frac{x^2 - 4}{x - 2} = \frac{(x+2)(x-2)}{x-2} = x + 2 has a hole at x=2x = 2, but the limit is 44.

Your Task

Implement double limit(double (*f)(double), double x, double h) that approximates the limit of ff at xx using step size hh.

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