Here are approaches for single variable: tangent line and two variable functions (tangent plane). - Single variable function:
tg[f_, x_, p_] := (f'[x] /. x -> p) (x - p) + f[p] Here the argument f is function, x is symbol for differentiation and p is the x-value of point the line will be tangent to. - Example using a pure function:
q = #^3 - 3 #^2 &; Manipulate[ Plot[{q[x], tg[q, u, m] /. u -> x}, {x, -3, 3}, PlotRange -> {-5, 5}, Epilog -> {Red, PointSize[0.02], Point[{m, q[m]}]}], {m, -1, 1, 0.01}] - Visualizing:
- Tangent plane
tangent[f_, arg_, pt_] := (Grad[f @@ arg, arg] /. Thread[arg -> pt]).(arg - pt) + f @@ pt This is essentially a generalization of the previous code exploiting the gradient function and dot product. - Example:
w[x_, y_] := Sin[x] Cos[y]; - Visualizing:
ListAnimate[ Table[ Show[Plot3D[w[x, y], {x, -3, 3}, {y, -3, 3}, ViewVector -> {10, 10, 10}, PlotStyle -> Opacity[0.7]], Graphics3D[{Red, PointSize[0.03], Point[{Join[{j, j}, {Sin[j] Cos[j]}]}]}], Plot3D[Evaluate[(tangent[w, {x, y}, {j, j}] /. {x -> u, y -> v})], {u, j - 0.5, j + 0.5}, {v, j - 0.5, j + 0.5}, Mesh -> False, PlotStyle -> Green]], {j, -3, 3, 0.1}]]; |
0 Response to "How To Draw A Tangent To A Curve"
Post a Comment