如何使用 tikzpicture 环境绘制函数 x*(x-1)^(1/3) 的绝对值

如何使用 tikzpicture 环境绘制函数 x*(x-1)^(1/3) 的绝对值

我正在尝试f(x)=abs(x*(x-1)^(1/3))绘制[0,2]

绝对值(x*(x-1)^(1/3))

我必须使用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}

在此处输入图片描述

新年快乐!

相关内容