![为什么 (\x)^2 和 \x^2 在 Tikz 图中产生不同的结果?](https://linux22.com/image/283946/%E4%B8%BA%E4%BB%80%E4%B9%88%20(%5Cx)%5E2%20%E5%92%8C%20%5Cx%5E2%20%E5%9C%A8%20Tikz%20%E5%9B%BE%E4%B8%AD%E4%BA%A7%E7%94%9F%E4%B8%8D%E5%90%8C%E7%9A%84%E7%BB%93%E6%9E%9C%EF%BC%9F.png)
(\x)^2
将绘制正确的抛物线,而\x^2
负 x 分支将颠倒。为什么此公式需要 () 才能起作用?
\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.misc}
\begin{document}
\begin{figure}[!htb]
\begin{tikzpicture}
\draw[very thin,color=gray] (-4.1,-4.1) grid (4.1,4.1);
\draw[->] (-4.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,-4.2) -- (0,4.2) node[above] {$f(x)$};
\draw[thick,purple,domain=-3:3,smooth] plot (\x,{0.5*\x^2});
\draw[thick,brown,domain=-3:3,smooth] plot (\x,{0.2*\x^3});
\end{tikzpicture}
\caption{$y=1/2 x^2, y=1/5 x^3$}
\end{figure}
\end{document}
答案1
是()
必需的,以便指数可以正确地应用于负数。否则,我们有-5^2=-25
。以下是带括号和不带括号的输出:
笔记:
- 尽管这只会是偶数指数的问题,但我还是建议始终使用括号
(\x)
。
代码:
\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[very thin,color=gray] (-4.1,-4.1) grid (4.1,4.1);
\draw[->] (-4.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,-4.2) -- (0,4.2) node[above] {$f(x)$};
\draw[thick,purple,domain=-3:3,smooth] plot (\x,{0.5*\x^2}) node [right] {INCORRECT};
\draw[thick,brown,domain=-3:3,smooth] plot (\x,{0.2*\x^3}) ;
\begin{scope}[xshift=9cm]
\draw[very thin,color=gray] (-4.1,-4.1) grid (4.1,4.1);
\draw[->] (-4.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,-4.2) -- (0,4.2) node[above] {$f(x)$};
\draw[ultra thick,purple,domain=-3:3,smooth] plot (\x,{0.5*(\x)^2}) node [right] {CORRECT};
\draw[ultra thick,brown,domain=-3:3,smooth] plot (\x,{0.2*(\x)^3});
\end{scope}
\end{tikzpicture}
\end{document}