(\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}