Hi just wondering how to graph the tangent as well as this curve on the same graph : f(x)= Sin[x] at x=0 where the gradient of the tangent is 1
2 Answers
$\begingroup$
$\endgroup$
Here's some fun:
Manipulate[
Plot[Evaluate[{f[x], Normal@Series[f[x], {x, x0, 1}]}],
{x, -5, 5},
PlotRange -> {{-5, 5}, {-2, 2}},
Epilog -> {Red, PointSize[0.02], Point[{x0, f[x0]}]}],
{{x0, 0}, -4, 4},
{f, {Sin, Cos, Tan, 1/4 #^2 & -> "x^2/4"}}]
$\begingroup$
$\endgroup$
1
Another approach using derivative.
tangent[f_,x0_]:=(f^\[Prime])[x0] #1+First[b/. NSolve[f[x0]==(f^\[Prime])[x0] x0+b,b]]&;
Manipulate[Plot[Evaluate[{f[x], tangent[f, x0][x]}], {x, -5, 5},
PlotRange -> {{-5, 5}, {-2, 2}},
Epilog -> {Red, PointSize[0.02], Point[{x0, f[x0]}]}], {x0, -5,
5}, {f, {Sin, Cos,(.2 #^2 - 1.5) &}}]
-
$\begingroup$
tangent
appears to be undefined. $\endgroup$ Commented Feb 14, 2015 at 0:45
Plot[{Sin[x], x}, {x, -\[Pi], \[Pi]}]
? Or are you looking for an automated way to construct such plots for arbitrary $f$? $\endgroup$plotTangent[f_, x0_] := Plot[Evaluate[{f[x], Normal@Series[f[x], {x, x0, 1}]}], {x, x0 - 4, x0 + 4}]
, and then callplotTangent[f, 0]
, which produces the desired graph. $\endgroup$