![尝试使用 tikzpicture 绘制两个函数,其中一个是抛物线](https://linux22.com/image/420362/%E5%B0%9D%E8%AF%95%E4%BD%BF%E7%94%A8%20tikzpicture%20%E7%BB%98%E5%88%B6%E4%B8%A4%E4%B8%AA%E5%87%BD%E6%95%B0%EF%BC%8C%E5%85%B6%E4%B8%AD%E4%B8%80%E4%B8%AA%E6%98%AF%E6%8A%9B%E7%89%A9%E7%BA%BF.png)
我正在尝试绘制以下两个方程:
y = x
4x + y^2 = 12
第二个是抛物线。因此,我需要求 y。当我这样做时,我得到了一个平方根。因此,我将第二个方程分解为两个方程。然后,我使用以下 LaTex 代码来生成我的图。但是,我的抛物线的下半部分没有显示出来。我希望有人能告诉我原因。
\begin{tikzpicture}
\begin{axis}[
xmin = -12, xmax = 3,
ymin = -21, ymax = 12,
]
\addplot [
domain=-15:5, blue,
samples = 200,
smooth,
thick,
] {x};
\addplot [
domain=-20:3, blue,
samples = 200,
smooth,
thick,
] {sqrt(12-4*x)};
\addplot [
domain=3:20, blue,
samples = 200,
smooth,
thick,
] {-sqrt(4*x-12)};
\end{axis}
答案1
您在符号和域方面有错误 - 请记住向您的问题添加可编译代码。这是代码,使用颜色来区分图表:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [
domain=-20:3, red,
samples = 200,
smooth,
thick,
] {x};
\addplot [
domain=-20:3, green,
samples = 200,
smooth,
thick,
] {sqrt(12-4*x)};
\addplot [
domain=-20:3, blue,
samples = 200,
smooth,
thick,
] {-sqrt(12-4*x)};
\end{axis}
\end{tikzpicture}
\end{document}