How can I plot a function in latex?for example, if I simply want to draw a decreasing function in first quadrant say f(x) = 1/x and draw dashed line to join (2,0) to (2,1/2) and solid line to join (2,1/2) to (0,1/2).
Asked
Active
Viewed 458 times
0
1 Answers
1
The best way to learn is experimenting, you could try using tikz and pgfplots:
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 0, xmax = 30,
ymin = 0, ymax = 2.0]
\draw [dashed] (2, 0) -- (2, 0.5);
\draw (2, 0.5) -- (0, 0.5);
\addplot[
domain = 0:30,
samples = 100,
smooth,
thick,
] {1/x};
\end{axis}
\end{tikzpicture}
\end{document}
Jaap
- 359
-
-
Thank you for answering. Can you please add how to label axes as X and Y and function as f(x) and lines as x=a and y=b on this picture. It will be very helpful. – UserA Nov 30 '21 at 10:06
-
Add
xlabel={x-axis label}andylabel={y-axis label}to the\begin{axis}command – Jaap Nov 30 '21 at 11:18

latex plot function– gernot Nov 25 '21 at 11:23tikzpictureenvironment you can do\draw (2, 0) -- (2, 0.5);to draw a line from (2, 0) to (2, 0.5). For more complicated plots there is a plot command,\draw plot (\x, f(\x));wherefis some function that either you define or a built in function. For even more complicated plots have a look at pgfplots. – Willoughby Nov 25 '21 at 11:25