![pgfplots を使用して有理指数を含む関数をプロットするにはどうすればよいですか?](https://rvso.com/image/327790/pgfplots%20%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%E6%9C%89%E7%90%86%E6%8C%87%E6%95%B0%E3%82%92%E5%90%AB%E3%82%80%E9%96%A2%E6%95%B0%E3%82%92%E3%83%97%E3%83%AD%E3%83%83%E3%83%88%E3%81%99%E3%82%8B%E3%81%AB%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%82%88%E3%81%84%E3%81%A7%E3%81%99%E3%81%8B%3F.png)
プロットしようとしているべき乗関数が完全に表示されません。ドメインなどを変更してみましたが、効果がありません。助けていただけないでしょうか?
\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xlabel = $x$,
ylabel = {$y$},
xmax = {4},
xmin = {-1},
ymax = {2},
ymin = {-2},
legend pos = outer north east
]
\addplot [
domain=-10:10,
samples=100,
color=black,
]
{x^(1/2)};
\addlegendentry{$y=\sqrt{x}$}
\addplot [
domain=-5:5,
samples=100,
color=blue,
]
{x^(1/4)};
\addlegendentry{$y=x^{\frac{1}{4}}$}
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xlabel = $x$,
ylabel = {$y$},
xmax = {4},
xmin = {-4},
ymax = {2},
ymin = {-2},
legend pos = north west
]
\addplot [
domain=-10:10,
samples=100,
color=black,
]
{x^(1/3)};
\addlegendentry{$y=x^{\frac{1}{3}}$}
\addplot [
domain=-10:10,
samples=100,
color=blue,
]
{x^(1/5)};
\addlegendentry{$y=x^{\frac{1}{5}}$}
\end{axis}
\end{tikzpicture}
\end{document}
答え1
ソリューションは次のように適応できます。立方根を計算するPGF数学関数3 乗根と 5 乗根を計算する関数を生成します。
参考文献:
コード:
\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\pgfmathdeclarefunction{CubeRoot}{1}{%
\pgfmathparse{ifthenelse(#1<0,-1,1)*exp((ln(abs(#1)))/3)}%
}
\pgfmathdeclarefunction{FifthRoot}{1}{%
\pgfmathparse{ifthenelse(#1<0,-1,1)*exp((ln(abs(#1)))/5)}%
}
\begin{document}\noindent
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xlabel = $x$,
ylabel = {$y$},
xmax = {4},
xmin = {-1},
ymax = {2},
ymin = {-2},
legend pos = south east
]
\addplot [
domain=0:4,
samples=100,
color=orange,
line width=1.0pt,
]
{(x)^(1/2)};
\addlegendentry{$y=\sqrt{x}$}
\addplot [
domain=0:5,
samples=100,
color=blue,
line width=1.0pt,
]
{(x)^(1/4)};
\addlegendentry{$y=x^{\frac{1}{4}}$}
\end{axis}
\end{tikzpicture}
\par
\noindent
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xlabel = $x$,
ylabel = {$y$},
xmax = 4,
xmin = -4,
ymax = 2,
ymin = -2,
legend pos = south east,
clip=true,
]
\addplot [
domain=-4:4,
samples=100,
color=blue,
line width=1.0pt,
]
{CubeRoot(x)};
\addlegendentry{$y=x^{\frac{1}{3}}$}
\addplot [
domain=-4:4,
samples=100,
color=red,
line width=1.0pt,
]
{FifthRoot(x)};
\addlegendentry{$y=x^{\frac{1}{5}}$}
\end{axis}
\end{tikzpicture}
\end{document}