私の関数は適切な範囲をプロットしません

私の関数は適切な範囲をプロットしません

簡単な関数をプロットしようとしています: y = sqrt(x+4)-2:

\begin{tikzpicture}
   \begin{axis}[ 
        xlabel=$x$,
        ylabel={$y$},
        axis x line=center, axis y line=center
        ] 
        \addplot[domain=-5:5,
        color=red] {sqrt(x+4)-2}; 
    \end{axis}
 \end{tikzpicture}

次のような結果になります:

ここに画像の説明を入力してください

x = -4 で最小 y 値は -2 になるはずですが、-1.5 になります。どうしてでしょうか? ありがとうございます!

答え1

  • 定義するにはdomain=-5:5pgfplots以下に-4複雑な関数を描画する必要がありますが、これは不可能です。したがって、下限の定義域は であることが賢明です-4
  • 関数の接線はx=-4直交しているので、デフォルトのサンプル数は関数の変化に追従できるほど小さい。

最も簡単な解決策は

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}
\begin{tikzpicture}
   \begin{axis}[
        xlabel=$x$,
        ylabel={$y$},
        axis lines=center,
       %samples=400% for more smuth curve
            ]
   \addplot[domain=-4:5, color=red] {sqrt(x+4)-2};
   \end{axis}
 \end{tikzpicture}
 \end{document}

これにより

ここに画像の説明を入力してください

答え2

描いているものが反転した放物線であると認識しているだけであれば、大量のサンプルは必要ありません。

\documentclass[margin=3pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}
\begin{tikzpicture}
   \begin{axis}[
        xlabel=$x$,
        ylabel={$y$},
        axis lines=center]
   \addplot[domain=-2:1.5, color=red] ({(x+2)^2-4},{x});
   \end{axis}
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報