f(x)={-x for -l<x≤0
& 0 otherwise}
如何绘制上述方程式。请帮忙。也解释一下
答案1
我建议你使用这个pgfplots
包。由于你的函数有三个区间,我将图分成了这三个
0 for x ≤ -l
-x for -l < x ≤ 0
0 for 0 < x
在 处有一个不连续点x = -l
,因此我在 处画了一个实心圆,f(-l) = 0
在 处画了一个空心圆f(-l) = l
。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$},ylabel={$f(x)$},
xtick={-1,0},xticklabels={$-l$,$0$},
ytick={0,1},yticklabels={$0$,$l$},
no marks,
]
\addplot[blue,domain=-2:-1] {0};
\addplot[blue,domain=-1:0] {-x};
\addplot[blue,domain=0:2] {0};
\node[blue,draw,fill=blue ,circle,inner sep=1pt] at (axis cs:-1,0) {};
\node[blue,draw,fill=white,circle,inner sep=1pt] at (axis cs:-1,1) {};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
也许你喜欢画单锯齿......
借助 TikZ,这很容易:
\documentclass[border=3mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[ ->] (0,-0.1) node[below] {0} -- (0,2) node[below right] {$f(x)$};
\draw[<->] (-3,0) node[below] {$-\infty\gets x$} --
( 3,0) node[below] {$x \to +\infty$};
\draw (-0.1,1) node[left] {1} -- + (0.2,0);
\draw (-1,0.1) -- + (0,-0.2) node[below] {$-1$};
%
\draw[very thick,red] (-2.5,0) -- (-1,0)
(-1.0,1) -- (0,0)
( 0.0,0) -- (2.5,0);
\draw[very thin,dashed,red] (-1,0) -- (-1,1);
\end{tikzpicture}
\end{document}
答案3
为了显得古怪,让我们添加一个gnuplot
混合解决方案!:)
% arara: pdflatex: { shell: yes }
\documentclass{article}
\usepackage{gnuplottex}
\begin{document}
\begin{gnuplot}[terminal=pdf]
set key inside left top vertical Right noreverse enhanced autotitles box linetype -1 linewidth 1.000
f(x) = -1 < x && x <= 0 ? -x : 0
plot f(x)
\end{gnuplot}
\end{document}
输出:
答案4
另一种方式韓式,一个非常高效的 LaTeX 接口MetaPost:
\documentclass[border=2mm]{standalone}
\usepackage[metapost]{mfpic}
\setlength{\mfpicunit}{1cm}
\opengraphsfile{\jobname}
\begin{document}
\begin{mfpic}[3]{-2.5}{1.5}{-0.5}{1.5}
\doaxes{xy}
\dashed\lines{(-1, 1), (0, 1)}
\drawcolor{red}
\dashed\lines{(-1, 0), (-1, 1)}
\penwd{1bp}
\lines{(\xmin, 0), (-1, 0)}
\lines{(-1, 1), (0, 0), (\xmax-.04, 0)}
\pointcolor{red}
\point[4pt]{(-1, 0)}
\pointfillfalse
\point[4pt]{(-1, 1)}
\tlpointsep{3bp}
\tlabels{[tc](\xmax, 0){$x$} [cr](0, \ymax){$y$} [tr](0, 0){$O$}
[tc](-1, 0){$-1$} [br](0, 1){$1$}}
\end{mfpic}
\closegraphsfile
\end{document}
先用 LaTeX 编译,再用 MetaPost 编译,然后再用 LaTeX 编译。结果: