我正在尝试f(x)=abs(x*(x-1)^(1/3))
绘制[0,2]
:
我必须使用tikzpicture
环境,但我无法以一种好的方式来做到这一点。
梅威瑟:
\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{center}
\begin{tikzpicture}[declare function={f(\x)=ifthenelse(\x>=0&&\x<=1,abs(\x*(\x-1)^(1/3)),\x*(\x-1)^(1/3));}]
\begin{axis}[
axis on top,
legend pos=outer north east,
axis lines = center,
xticklabel style = {font=\tiny},
yticklabel style = {font=\tiny},
xlabel = $x$,
ylabel = $y$,
legend style={cells={align=left}},
legend cell align={left},
]
\addplot[very thick,red,samples=81,domain=0:2,name path=f] {f(x)};
\end{axis}
\end{tikzpicture}
\end{center}
如果我尝试,会产生相同的效果\addplot[very thick,red,samples=81,domain=0:2,name path=f] {abs(x*(x-1)^(1/3))};
:
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis on top,
legend pos=outer north east,
axis lines = center,
xticklabel style = {font=\tiny},
yticklabel style = {font=\tiny},
xlabel = $x$,
ylabel = $y$,
legend style={cells={align=left}},
legend cell align={left},
]
\addplot[very thick,red,samples=81,domain=0:2,name path=f] {abs(x*(x-1)^(1/3))};
\end{axis}
\end{tikzpicture}
\end{center}
谢谢,祝你 2 月 19 日愉快0
!
答案1
你以编译器认为的方式设置括号(x-1)^(1/3)
。它不知道如何绘制负数的三次方根,就这样吧。我修复了括号,得到
\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{center}
\begin{tikzpicture}[declare function={f(\x)=ifthenelse(\x>=0&&\x<=1,\x*abs(\x-1)^(1/3),\x*(\x-1)^(1/3));}]
\begin{axis}[
axis on top,
legend pos=outer north east,
axis lines = center,
xticklabel style = {font=\tiny},
yticklabel style = {font=\tiny},
xlabel = $x$,
ylabel = $y$,
legend style={cells={align=left}},
legend cell align={left},
]
\addplot[very thick,red,samples=161,domain=0:2,name path=f] {f(x)};
\end{axis}
\end{tikzpicture}
\end{center}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis on top,
legend pos=outer north east,
axis lines = center,
xticklabel style = {font=\tiny},
yticklabel style = {font=\tiny},
xlabel = $x$,
ylabel = $y$,
legend style={cells={align=left}},
legend cell align={left},
]
\addplot[very thick,red,samples=161,domain=0:2,name path=f] {abs(x)*abs(x-1)^(1/3)};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
新年快乐!