tikz で $\ln(x+\sqrt{x^2-1})$ を描く方法

tikz で $\ln(x+\sqrt{x^2-1})$ を描く方法

これを試したけどうまくいかない

\def\Xmin{-2} \def\Xmax{2} 
\def\Ymin{-2} \def\Ymax{2} 
\def\Xunit{1.5cm} \def\Yunit{1.5cm} 
\def\Xleg{\small \sffamily $x$} % légende en abscisse 
\def\Yleg{\small \sffamily $y$} % légende en ordonnées 
\begin{tikzpicture}[x=\Xunit,y=\Yunit] 
\draw[>= latex,->,thick](\Xmin,1)--(\Xmax,1); 
\draw[>= latex,->,thick](1,\Ymin)--(1,\Ymax); 
\draw [domain=\Xmin:\Xmax,thick,red] plot (\x,{(ln(\x+(sqrt{((\x)^2}-1)))});
\end{tikzpicture}

答え1

LaTeXでできることを手作業で行うのではなく、pgfplots自動軸を含むより優れたプロット機能を追加するために使用してください。

注意:pgfplots 可能ですが、組み込みのチェックで保存されません。たとえば、提案されたドメイン[-2,2]では、関数は定義されていないx+sqrt{x^2-1}負の数に切り込まれますln。そして、エラーが発生します。

! Package PGF Math Error: I cannot calculate the logarithm of -0.26794

しかし、pfdplots問題が起こらないようにチェックが組み込まれているので、ここでドメインを指定すると[-2,2]pgfplots影響を受ける領域には何もプロットされなくなります。

私がetcで行ったように、オプションに手動でyminと を追加することもできます。ymaxaxisxmin

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    unbounded coords=jump,
    domain=-2:2,
    xmin=-2,
    xmax=2,
    ]
    \addplot[red,smooth] {ln(\x+(sqrt((\x)^2-1)))};
  \end{axis}
\end{tikzpicture}
\end{document}

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


以下は、元の関数と内部関数の動作を示す例です。

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    unbounded coords=jump,
    domain=-2:2,
    axis lines=middle,
    legend style={at={(-0.015,0.95)},anchor=north west,cells={anchor=west}},
    ]
    \addplot[red,smooth,samples=1001] {ln(\x+(sqrt((\x)^2-1)))};
    \addlegendentry{$\ln(x+\sqrt{x^2-1})$}
    \addplot[blue,smooth,samples=1001] {x+sqrt((\x)^2-1)};
    \addlegendentry{$x+\sqrt{x^2-1}$}
  \end{axis}
\end{tikzpicture}
\end{document}

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

関連情報