# Draw tangent to curve at intersection

I am trying to see if there is any way to simplify the following code: I have several functions, and one line. I would like to draw the tangent of each functions where they intersect the line.

Currently all is done manually: I calculated the coordinate manually, as well as the slope. I was wondering if there was anyway to simplify, especially given the fact that we can get the intersection of the line and the functions using the tikz library intersections.

Thanks in advance for the help.

Here is my code:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
[declare function={ f(\x,\a)   = \a/\x;}]

\begin{axis}[xmin= 0, xmax = 5,ymin=0, ymax = 5,]

\path [name intersections={of=ray1 and IC1}]; %not used

\addplot [blue] coordinates {({sqrt(1/3) + 0.2},{sqrt(3*1) -0.6}) ({sqrt(1/3) - 0.2},{sqrt(3*1) +0.6})};
\addplot [blue] coordinates {({sqrt(3/3) + 0.2},{sqrt(3*3) -0.6}) ({sqrt(3/3) - 0.2},{sqrt(3*3) +0.6})};
\addplot [blue] coordinates {({sqrt(5/3) + 0.2},{sqrt(3*5) -0.6}) ({sqrt(5/3) - 0.2},{sqrt(3*5) +0.6})};

\end{axis}

\end{tikzpicture}
\end{document}


• Welcome on Tex.SE Apparently, you'd like to draw the tangents of indifference curves (?). Take a look at tex.stackexchange.com/questions/60392/… and maybe also tex.meta.stackexchange.com/questions/8521/… to use Google for visual search of keywords
– JeT
Jun 24 '20 at 15:40
• Have a look here tex.stackexchange.com/questions/477206/… Jun 24 '20 at 16:29
• In this case, since you can calculate explicitly derivative of the function, you can get the intersection point of the line and the function using the tikz library intersections, then get x-coordinate of the intersection point, then formulate the equation of the tangent line, and draw. Note that with Asymptote, everything is much easier! Jun 25 '20 at 10:17