plot a function associated with some horizontal finite lines [duplicate]

I am going to plot the function y[x_]:=1/x associated with horizontal finite lines. For example at y=-12,8, -6.5, -5.5, -5.0. Can anyone help me to plot it?

2 Answers

Try this:

Show[{
Plot[-(1/x), {x, 0.06, 1}, PlotRange -> {-13, 0.1}],
Graphics[{Red,
Line[{{0, #}, {-(1/#), #}}]}] & /@ {-12, -8, -6.5, -5.5, -5.0}
}]


yielding

Have fun!

Following is the layman's way (Non-technical) to plot the required plot;

Here I am plotting each finite line from $$0$$ to intersection point of the line with the curve ($$-1/x$$). This intersection point (endpoint of the line) can be found by equating: $$-1/x=-12 \rightarrow x=1/12$$)

  y[x_] := -1/x
p1 = Plot[{-12}, {x, 0, 1/12}]
p2 = Plot[y[x], {x, 0, 1}]
Show[{p1, p2}, PlotRange -> All]


You can combine all the lines in a single plot.

   y[x_] := -1/x
p1 = Table[Plot[{-1/n}, {x, 0, n}], {n, {1/12, 1/8, 1/6.5, 1/5.5,1/5}}];
p2 = Plot[y[x], {x, 0.0, 1}]
Show[{p1, p2}, PlotRange -> All]


• finite lines!!! I think your lines are not finite. Oct 9 '18 at 8:43
• @monfneg, Hey, I have modified.
– 2.1
Oct 9 '18 at 9:05