Any shortcut command of finding a tangent line and tangent point to a curve that's explicitly or implicitly defined? The focus is on implicit curves.
An implicit curve could be sth like $(x/exp(y)-1)^2-y^2=1$
Any shortcut command of finding a tangent line and tangent point to a curve that's explicitly or implicitly defined? The focus is on implicit curves.
An implicit curve could be sth like $(x/exp(y)-1)^2-y^2=1$
Edit
f[x,y]==0
, the normal of the tangent line is Grad[f[x,y],{x,y}]
, so the tangent line of the f[x,y]==0
is({x, y} - {x0, y0}) . Grad[f[x, y], {x, y}] == 0
Here {x0,y0}
is the arbitary pont on the tangent line.
ImplicitRegion
and DiscretizeRegion
to solve the equation.(since NSolve
,Reduce
or FindRoot
does not work for this case)Clear["Global`*"];
f[x_, y_] = (x - Exp[y] - 1)^2 - y^2 - 1;
{x0, y0} = {-5, -3};
reg = ImplicitRegion[{({x, y} - {x0, y0}) . Grad[f[x, y], {x, y}] ==
0, f[x, y] == 0}, {x, y}];
pts = MeshPrimitives[DiscretizeRegion[reg, {{-10, 10}, {-10, 10}}],
0][[;; , 1]]
ContourPlot[f[x, y] == 0 // Evaluate, {x, -10, 10}, {y, -10, 10},
Epilog -> {Blue, Point[{x0, y0}], Red, Point[pts], Red,
Arrowheads[{{.05, .8}}], Arrow[{{x0, y0}, #}] & /@ pts}]
{x0, y0} = {1, 1}
, there are three tangent lines through {x0,y0}={1,1}
.( so there are three tangent points)Clear["Global`*"];
Manipulate[
Module[{f, reg, dreg, pts},
f[x_, y_] = (x - Exp[y] - 1)^2 - y^2 - 1;
{x0, y0} = pt;
reg = ImplicitRegion[{({x, y} - {x0, y0}) . Grad[f[x, y], {x, y}] ==
0, f[x, y] == 0}, {x, y}];
pts = MeshPrimitives[DiscretizeRegion[reg, {{-10, 10}, {-10, 10}}],
0][[;; , 1]];
ContourPlot[f[x, y] == 0 // Evaluate, {x, -10, 10}, {y, -10, 10},
Epilog -> {Blue, Point[{x0, y0}], Red, Point[pts], Red,
Arrowheads[{{.05, .8}}], Arrow[{{x0, y0}, #}] & /@ pts},
PerformanceGoal -> "Quality"]], {{pt, {0, 0}}, Locator}]
Original
It seems that it is not easy to find all of the tangent lines for any point {x0,y0}
outside the curve. Here we only plot one tangent line from a point does not on the curve.
Clear["Global`*"];
f[x_, y_] = (x - Exp[y] - 1)^2 - y^2 - 1;
{x0, y0} = {-5, -3};
sol = FindInstance[{({x, y} - {x0, y0}) . Grad[f[x, y], {x, y}] == 0,
f[x, y] == 0}, {x, y}, Reals, 1]
pts = {x, y} /. sol // N
ContourPlot[f[x, y] == 0 // Evaluate, {x, -10, 10}, {y, -10, 10},
Epilog -> {Blue, Point[{x0, y0}], Red, Point[pts], Red,
Arrow[{{x0, y0}, #}] & /@ pts}]
Take a look at the Applications section in the documentation for ImplicitD
. Note that ImplicitD
has been available only since version 13.1.
(* Define your curve *)
curve = (x - Exp[y] - 1)^2 - y^2 == 1;
(* Calculate the appropriate partial derivative *)
slope = ImplicitD[curve, y, x];
(* Find points on the curve at x = -1 and x = 4 *)
points = FindInstance[curve && (x == -1 || x == 4), {x, y}, Reals, 4];
(* Define tangent lines *)
tangents = InfiniteLine[{x, y}, {1, slope}] /. points;
(* Plot the curve and tangent lines *)
Show[ContourPlot @@ {curve, {x, -5, 5}, {y, -5, 5}},
Graphics[{{Red, PointSize[Medium], Point[{x, y}] /. points}, {Orange,
Dashed, tangents}}]]
f[x_, y_] = (x - Exp[y] - 1)^2 - y^2 - 1;
df = ImplicitD[f[x0, y0] == 0, y0, x0];
pts = NSolve[f[x0, y0] == 0 && (x0 == -1 || x0 == 4), {x0, y0}, Reals]
{{x0 -> -1., y0 -> -1.9024}, {x0 -> 4., y0 -> -2.76129},
{x0 -> 4., y0 -> 0.60499}, {x0 -> 4., y0 -> 1.58371}}
tangent = (x - x0)*df + y0 /. pts // Expand
{-0.935624 + 0.966771 x, 1.79955 - 1.14021 x,
-1.09796 + 0.425737 x, 0.590528 + 0.248296 x}
Show[Plot[tangent, {x, -3, 6}, PlotStyle -> Dashed,
Epilog -> {Red, PointSize -> Large, Point[{x0, y0} /. pts]}],
ContourPlot[f[x, y] == 0, {x, -5, 6}, {y, -5, 5}, ContourStyle -> Thick], AspectRatio -> 1]
For versions below 13.1 you can replace ImplicitD with the following version:
df = -D[f[x0, y0], x0]/D[f[x0, y0], y0] // Simplify
A shortcut command of finding a tangent line is given by ResourceFunction:
tangent = ResourceFunction["TangentLine"];
The function is bijective at x = -1.
tangent[(x - Exp[y] - 1)^2 - y^2 == 1, {x, -1}, y] // N // Dataset
At x = 4 the function is surjective. You get only one tangentline at [4, 0.60499].
tangent[(x - Exp[y] - 1)^2 - y^2 == 1, {x, 4}, y] // N // Dataset
There is a note in the description:
If only one coordinate of the intersection point is given, the other coordinate is inferred. For expressions that are multivalued at the given value of x or y, information on only one of potentially several tangent lines is returned.