# How to draw tangents to a curve and obtain the corresponding angle?

I'm trying to solve an equation and plot the solutions in the complex plane:

   Solve[Rationalize[E^(-b (1.365)) + E^(-b (-0.350)) + E^(-b (-0.378)), 0] == 0, b]
ListPlot[ReIm[b /. % /. C[1] -> 0], ImageSize -> Large]


Here is the plot:

Now, I need to draw tangent lines on the middle curve at the point where it is crossing the real axis, and obtain the angle. It is possible to do it by hand on the paper, but can one also do it by Mathematica?

The goal is to find the slope where the solution crosses the real or x-axis. The solution is a list of points, and your graph shows their positions, but the points are in an inconvenient order which is apparent with Joined -> True. We can use DerivativeFilter to compute a slope value at each point, but we need to rearrange the points from the solution.

solution =
Solve[Rationalize[
E^(-b (1.365)) + E^(-b (-0.350)) + E^(-b (-0.378))] == 0, b];
ListPlot[ReIm[b /. solution /. C[1] -> 0],
Joined -> True, Mesh -> True]


We can sort the points into order by real and imaginary coordinates, where $$x$$ is the real axis and $$y$$ is the imaginary axis. However, reverse the real and imaginary axes so that we can use DerivativeFilter. Superimpose the solution and the computed slopes on the same graph.

points = Sort[Reverse /@ N@ReIm[b /. solution /. C[1] -> 0]];
der = Transpose[{points[[All, 1]],
DerivativeFilter[points, {1}][[All, 2]]}];
ListLinePlot[{points, der}, PlotRange -> All,
PlotLabels -> {"solution", "slope"}]


We need the slope where the solution crosses the real, $$y$$ axis. First, find the average interval of points along the x-axis, and use the interval to find some points that are near the y-axis. The average of these values near the y-axis is an approximation of the slope. We find the slope is .0, and therefore the angle is the arctangent of the slope.

meanX = Mean[
Differences[First /@ points]];(*average interval along x-axis*)

pointsNearY = Extract[der, Position[
points,
p_List /;
IntervalMemberQ[Interval[{-4 meanX, 4 meanX}], First[p]]]];
Mean[Last /@ pointsNearY](*average slope near the y-axis*)
ListPlot[pointsNearY,
Joined -> True, Mesh -> All,
PlotLabel -> "computed slope near y-axis"]


Yes, the solution points don't have a zero-value on the real axis, but the solution does cross the axis, as we can see in the graph of the computed slopes; the interpolated value is 0. When the axes are not rotated, the interpolated value is $$π$$/2.

The two solution points on either side of the real axis are easy to locate.

pointsNearRealAxis =
Complex @@@
Extract[Reverse /@ points,
Position[Reverse /@ points,
p_List /; IntervalMemberQ[Interval[{-meanX, meanX}], Last[p]]]]

Show[ListLinePlot[Reverse /@ points],
ListPlot[ReIm@pointsNearRealAxis,
PlotStyle -> Directive[Red, PointSize[Large]]]]


{-0.400717 - 1.81708 $$i$$, -0.400717 + 1.81708 $$i$$}

• @Davood, I've added a way to find the closest points to the real axis. Aug 2, 2021 at 19:38
• It's correct to say that if we had a smooth curve (we don't), the slope at the intersection with the real-axis would be $π$/2. Instead, the solution is a set of discrete points, and we've found a slope for each of them. The intersection with the real axis is between the two points. The 0. value is the interpolation of the slopes at the two points. However, the intersection of the two tangent lines is not the crossing-point of the real axis. Generally, tangents to two similar points on either side of an inflection point (the real axis crossing-point) do not meet at the inflection point. Aug 2, 2021 at 21:27