答案1
使用\piecewise
来自的函数此解决方案,你可以选择合适的函数。我选择了 x^2 和 2x–x^2。
以下是代码:
\documentclass{article}
\usepackage{tikz}
\newcommand{\piecewise}[1]{
\foreach \f/\a/\b/\open/\closed in {#1}{%
\draw[domain=\a:\b, smooth, variable=\x] plot ({\x}, \f);
\foreach \x[evaluate={\y=\f;}] in \open{%
\draw[fill=white] (\x,\y) circle (.6mm);
}
\foreach \x[evaluate={\y=\f;}] in \closed{%
\fill (\x,\y) circle (.6mm);
}
}
}
\begin{document}
\begin{tikzpicture}
\draw[-stealth] (-2, 0) -- (3.5, 0) node[right] {$x$};
\draw[-stealth] (0, -1.5) -- (0, 2.5) node[above] {$y$};
\draw[fill] (.6,0) circle(.6mm) node[below, yshift=-1] {$x_0$};
\begin{scope}[line width=1pt, blue]
\piecewise{{\x*\x}/-1.5/.6/{.6}/{},{2*\x-\x*\x}/.6/2.5/{}/{.6}}
\end{scope}
\end{tikzpicture}
\end{document}