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:

    [declare function={ f(\x,\a)   = \a/\x;}]

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

    \addplot[black,domain=0.3:4.5,name path= IC1] {f(\x,1)}; 
    \addplot[black,domain=0.7:4.5,name path= IC2] {f(\x,3)}; 
    \addplot[black,domain=1:4.5,name path= IC3] {f(\x,5)}; 

    \addplot[blue,dashed,name path = ray1] {3*\x};

    \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})};



enter image description here

  • 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, 2020 at 15:40
  • Have a look here tex.stackexchange.com/questions/477206/…
    – Black Mild
    Jun 24, 2020 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!
    – Black Mild
    Jun 25, 2020 at 10:17

1 Answer 1


Using the tzplot package:

enter image description here



% plot graphs
\def\ICa{1/\x}          \def\ICb{3/\x}          \def\ICc{5/\x}
\tzfn\ICa[0.3:4.5]      \tzfn\ICb[0.7:4.5]      \tzfn\ICc[1.0:4.5]
% intersections
\tzXpoint*{ray}{ICa}(A) \tzXpoint*{ray}{ICb}(B) \tzXpoint*{ray}{ICc}(C)
% tangent lines


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .