Lesson 4 of 18

Tangent Line

Tangent Line

The tangent line at a point (x0,f(x0))(x_0, f(x_0)) is the line that just touches the curve there, with slope equal to f(x0)f'(x_0).

Equation

y=f(x0)+f(x0)(xx0)y = f(x_0) + f'(x_0) \cdot (x - x_0)

This is the point-slope form of a line, using the derivative as the slope.

Linearization

The tangent line is also called the linear approximation (or linearization) of ff near x0x_0:

f(x)f(x0)+f(x0)(xx0)for x near x0f(x) \approx f(x_0) + f'(x_0) \cdot (x - x_0) \quad \text{for } x \text{ near } x_0

This is the foundation of calculus-based approximation. It says: near any point, a smooth curve looks like a straight line.

Example

For f(x)=x2f(x) = x^2 at x0=3x_0 = 3:

  • f(3)=9f(3) = 9
  • f(3)=6f'(3) = 6
  • Tangent line: y=9+6(x3)=6x9y = 9 + 6(x - 3) = 6x - 9
  • At x=4x = 4: y=15y = 15 (exact: f(4)=16f(4) = 16, error = 1 — small for nearby xx)

Normal Line

The normal line is perpendicular to the tangent:

y=f(x0)1f(x0)(xx0)y = f(x_0) - \frac{1}{f'(x_0)} \cdot (x - x_0)

Your Task

Implement double tangent_y(double (*f)(double), double x0, double x, double h) that returns the y-value of the tangent line at x0x_0, evaluated at xx. Use the central difference formula to compute f(x0)f'(x_0).

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