我想绘制函数图形x^(-2/3)在域 1:2 和 -2:-0.1 中。但对于负数,我遇到了错误(见下文)。我不知道如何为 tikz 命令 \addplot 中使用的 gnuplot 设置数字格式“%.7e”。也许问题出在其他地方。
接下来,我发现 gnuplot 无法绘制函数 x^(-2/3),只能绘制 x^(-0.6666)。我收到消息空 y 范围 [1:1]
Xelatex 错误:
set format "%.7e";; set samples 100; set dummy x; plot [x=-2:-0.1] x**(-0.666); ^
%%"example.pgf-plot.gnuplot", line 2: all points y value undefined!
代码:
\documentclass{scrbook}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}[thick,scale=0.7,
every node/.style={transform shape} ]
\begin{axis}[
xmin = -1.5, xmax = 2.5, ymin = 0, ymax = 3.5, % osy
domain = -1:3.5,
restrict y to domain=0:3,
axis equal image,
axis x line = middle,
axis y line = middle,
xlabel={$x$}, ylabel={$y$},
]
\addplot[color=red, samples=100, smooth, ultra thick, unbounded coords=jump, no markers,
domain = 0.1:2] gnuplot{x^(-0.666)};
\addplot[color=red, samples=100, smooth, ultra thick, unbounded coords=jump, no markers,
domain = -2:-0.1] gnuplot{x^(-0.666)};
\end{axis}
\end{tikzpicture}
\end{document}
该图形应该关于 y 轴对称,但事实并非如此。
答案1
的情节y=x^(-2/3)
是不关于 y 轴对称(也许你其实是在策划y=1/(cuberoot(x^2))
?)。
对于负值x
,您将得到一个复杂的结果。您可以使用 gnuplot 函数提取结果的实部real
,然后绘制该图:
如果你真的想画图(在正域中y=1/(cuberoot(x^2))
等于),你可以使用。这会给你一个关于 y 轴对称的函数:x^(2/3)
1/(x^2)^(1./3)
\documentclass{scrbook}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}[thick,scale=0.7,
every node/.style={transform shape} ]
\begin{axis}[
xmin = -2.5, xmax = 2.5, ymin = -3.5, ymax = 3.5, % osy
restrict y to domain=-3:3,
axis equal image,
axis x line = middle,
axis y line = middle,
xlabel={$x$}, ylabel={$y$},
]
\addplot[color=red, samples=100, smooth, ultra thick, unbounded coords=jump, no markers,
domain = 0.1:2] gnuplot{x^(-2.0/3)};
\addplot[color=red, samples=100, smooth, ultra thick, unbounded coords=jump, no markers,
domain = -2:-0.1] gnuplot{real(x^(-2.0/3))};
\end{axis}
\end{tikzpicture}
\end{document}
\documentclass{scrbook}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}[thick,scale=0.7,
every node/.style={transform shape} ]
\begin{axis}[
xmin = -2.5, xmax = 2.5, ymin = -3.5, ymax = 3.5, % osy
restrict y to domain=-3:3,
axis equal image,
axis x line = middle,
axis y line = middle,
xlabel={$x$}, ylabel={$y$},
]
\addplot[color=red, samples=100, smooth, ultra thick, unbounded coords=jump, no markers,
domain = 0.1:2] gnuplot{1/((x^2)^(1./3))};
\addplot[color=red, samples=100, smooth, ultra thick, unbounded coords=jump, no markers,
domain = -2:-0.1] gnuplot{1/(x^2)^(1./3)};
\end{axis}
\end{tikzpicture}
\end{document}