2
$\begingroup$

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$

$\endgroup$
7
  • $\begingroup$ Welcome to Mathematica S.E. To start: 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, since the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) consider accepting the answer, if any, that solves your problem, by clicking checkmark sign, 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bmf
    Commented Feb 26, 2023 at 5:22
  • $\begingroup$ In general on this site we expect a concrete presentation of the task at hand, namely a proper mathematical formulation and some attempt made by you in code form. Also, we like having well-defined threads that deal with one problem at a time. Having said that, please take a moment to edit your question such that it meets the general guidelines of the site. $\endgroup$
    – bmf
    Commented Feb 26, 2023 at 5:24
  • 2
    $\begingroup$ The question is clear enough. If anyone knows of a Mathematica function that does this he can share. If not, there is no reason to complain about it. $\endgroup$
    – Bill Watts
    Commented Feb 26, 2023 at 6:20
  • $\begingroup$ thanks for supporting! The best mathematical exercise is through communication without using equations. If a question is explained clearly enough, there is no need to use equations. The shorter the question the better, saving people's time. $\endgroup$
    – feynman
    Commented Feb 26, 2023 at 8:59
  • $\begingroup$ @feyman But answering might be simplified if you do some work before. For example what is the implicit form of your curve, are you looking for 3D-curve? $\endgroup$ Commented Feb 26, 2023 at 10:08

3 Answers 3

7
$\begingroup$

Edit

  • For the implicit form of curve 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.

  • We use 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}]

enter image description here

  • We can test the pont {x0, y0} = {1, 1}, there are three tangent lines through {x0,y0}={1,1}.( so there are three tangent points)

enter image description here

  • animation.
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}]

enter image description here

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}]

enter image description here

$\endgroup$
8
$\begingroup$

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}}]]

Plot

$\endgroup$
2
$\begingroup$
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]

enter image description here

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

enter image description here

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

enter image description here enter image description here

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.