Skip to main content

calculus and analysis - Equation of a line that is tangent to a curve at point


A common problem in the derivative section of calculus texts is "find the equation of the line that is tangent to the curve $y = \ldots$ at the point $P$."


To find the line that is tangent to $y = 2 x \sin x$ at $(\pi/2,\pi)$, I'd do something like this in Mathematica:


y[x_] := 2 x Sin[x]
y[x] == y'[x] x + b /. x -> Pi/2;
bRule = Solve[%, b][[1]];

y == y'[a] x + b /. bRule /. a -> Pi/2

which outputs y == 2 x.


Is this more or less idiomatic Mathematica code? Is there a better way?



Answer



Certainly, there is a better way:


y[x_] := 2 x Sin[x]; a = Pi/2;
Collect[Normal[Series[y[x], {x, a, 1}]], x, Simplify]

Recall that the formula for a Taylor polynomial looks a bit like this:



$$f(x)=\color{red}{f(a)+f^\prime (a)(x-a)}+\frac{f^{\prime\prime}(a)}{2}(x-a)^2+\cdots$$


and reconciling this with the geometric interpretation of the Taylor polynomial as the best one-point osculatory (agrees at function and derivative values) approximation of a function shows why the approach works. I believe this should be a standard way to look at Taylor polynomials in the textbooks, if it already isn't.




Here is an equivalent approach:


Collect[InterpolatingPolynomial[{{{a}, y[a], y'[a]}}, x], x, Simplify]

This is based on the fact that the tangent line is the unique Hermite interpolating polynomial of degree $1$.




Certainly, one could do the plodding, "traditional" (whatever that means) approach:


y[x_] := 2 x Sin[x]; a = Pi/2;

Collect[y[a] + y'[a] (x - a), x, Simplify]

In any event, Solve[] is definitely unnecessary here.


Comments