Compute the equation of the tangent line, slope (derivative), and point of tangency for any real function f(x). Visualize the curve, tangent line, and the point of contact with dynamic scaling.
The tangent line to a curve at a given point is the straight line that "just touches" the curve at that point. Mathematically, it represents the best linear approximation of the function near that point, and its slope equals the derivative of the function at that point. This concept is fundamental to physics (instantaneous velocity), economics (marginal cost), engineering (optimization), and data science (gradient descent).
Tangent Line Equation: y = f'(x₀)(x - x₀) + f(x₀)
where f'(x₀) is the instantaneous rate of change (derivative) at x₀.
Given a function f(x) differentiable at x₀, the derivative is defined as f'(x₀) = lim_{h→0} [f(x₀+h)-f(x₀)]/h. Our calculator uses the central difference method for high accuracy: f'(x₀) ≈ (f(x₀+ε) - f(x₀-ε)) / (2ε) with ε = 1e-5. This method avoids analytical differentiation, making it compatible with any user‑defined function (sin, cos, exp, ln, polynomials, etc.). The tangent line is then constructed using point-slope form, and the graph is rendered with automatic boundary detection to capture the function's behavior around x₀.
For robustness, we preprocess the function expression: replace "^" with "**", convert "e^x" to "exp(x)", and bind `Math` functions. Invalid expressions or domain errors (e.g., log of negative) are caught and reported. Additionally, the tool detects potential non-differentiability by comparing left and right derivatives.
x (e.g., x^2 + 3*x - 5 or sin(x) + cos(x)).
| Function f(x) | x₀ | Slope f'(x₀) | Tangent Equation | Behavior Insight |
|---|---|---|---|---|
| x² | 1 | 2 | y = 2x - 1 | Tangent approximates parabola at vertex symmetry side |
| sin(x) | 0 | 1 | y = x | Linear approximation near origin, foundational for small‑angle approximation |
| eˣ | 0 | 1 | y = x + 1 | Exponential growth initially matches its derivative |
| ln(x) | 1 | 1 | y = x - 1 | Logarithmic curve near x=1 behaves like a line with slope 1 |
| x³ - 2x | 0.5 | -1.25 | y = -1.25x + 0.125 | Cubic with negative slope at that region |
Consider a particle moving along a line with position s(t) = t² - 4t + 5 meters. The tangent line at t = 3 seconds gives the instantaneous velocity: s'(3) = 2(3)-4 = 2 m/s. Using our calculator with f(x)=x^2 - 4*x + 5, x₀=3, we obtain slope = 2, tangent equation y = 2x - 4. The graph visually confirms the slope equals the velocity, demonstrating how differentiation captures motion dynamics.
The tangent line is not just a geometric curiosity; it is the core of differential calculus. The derivative f'(x₀) measures sensitivity to change: if you adjust x by a tiny amount Δx, the function changes by approximately f'(x₀)·Δx. This idea powers Newton's method for root-finding, gradient descent in machine learning, and the entire field of differential equations. Moreover, the tangent line defines the linearization of f at x₀, which is the first‑order Taylor polynomial.
Our calculator enables experimental learning: try f(x)=x^2 and increase x₀ from 0 to 2 — watch the tangent become steeper. For f(x)=sin(x), note that at x₀ = π/2, slope = 0 (horizontal tangent). Such insights are immediate with interactive visualization.
sin(x + PI) works correctly. Use "PI" or "E". You can also type "e" (lowercase) and it will be automatically recognized as Euler's number.