如何用 tikz $\frac12 \ln(\frac{x+1}{1-x})$绘制此函数?

如何用 tikz $\frac12 \ln(\frac{x+1}{1-x})$绘制此函数?

我的问题是它定义在]-1,1[所以我不知道如何写域

\def\Xmin{-1} \def\Xmax{1} 
\def\Ymin{-2} \def\Ymax{2} 
\def\Xunit{1cm} \def\Yunit{1cm} 
\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,0)--(\Xmax,0); 
\draw[>= latex,->,thick](0,\Ymin)--(0,\Ymax); 
\draw [domain=\Xmin:0,thick,red] plot (\x,{((1/2) (ln((1+\x)/(1-\x)))) });
\draw [domain=0:\Xmax,thick,red] plot (\x,{((1/2) (ln((1+\x)/(1-\x)))) });
\end{tikzpicture} 

我想要得到这样的东西

在此处输入图片描述

答案1

这是一个使用的解决方案pgfplots

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis lines = middle,
        xmin = -1.6,
        xmax = 1.6,
        > = Stealth
    ]
        \addplot[
            blue,
            thick,
            domain = -1:1,
            samples = 1000
        ]
            {0.5*ln((1+x)/(1-x))};
        \addplot[
            dashed,
            mark = none
        ]
            coordinates {(-1,-4) (-1,4)};
        \addplot[
            dashed,
            mark = none
        ]
            coordinates {(1,-4) (1,4)};
        \addplot[
            <->,
            thick,
            mark = none
        ]
            coordinates {(-1.1,-1.1) (1.1,1.1)};
    \end{axis}
\end{tikzpicture}
\end{document}

pgfplots 样本

答案2

当 x 趋近于 1 或 -1 时,函数y = 1/2 * ln((x + 1) / (x - 1))趋近于无穷大。此外,该函数不明确的在 x = 1 和 x = -1 处。因此,您只能在 范围内绘制此函数(-1 + delta, 1 - delta),其中delta是一个较小的正值。因此,

  • 绘图域更改为[-1 + \Xshift, 1 - \Xshift]其中\Xshift是一个较小的正数。
  • 为了模拟绘图范围,y 范围更改为[-3, 3]
\documentclass{article}
\usepackage{tikz}

\def\Xmin{-1} \def\Xmax{1} 
\def\Ymin{-3} \def\Ymax{3} 
\def\Xunit{1cm} \def\Yunit{1cm} 
\def\Xleg{\small \sffamily $x$} % légende en abscisse 
\def\Yleg{\small \sffamily $y$} % légende en ordonnées 

\def\Xshift{0.005} % \Xshift is not a good name, :(

\begin{document}
\begin{tikzpicture}[x=\Xunit,y=\Yunit]
  \draw[>= latex,->,thick] (\Xmin-.5, 0) -- (\Xmax+.5, 0); 
  \draw[>= latex,->,thick] (0, \Ymin)   -- (0, \Ymax);

  \draw [domain=\Xmin+\Xshift:\Xmax-\Xshift, samples=700, very thick, red] 
    plot (\x, {0.5*(ln((1+\x)/(1-\x)))});

  \draw[dashed] (\Xmin, \Ymin) -- (\Xmin, \Ymax);
  \draw[dashed] (\Xmax, \Ymin) -- (\Xmax, \Ymax);
\end{tikzpicture} 
\end{document}

由 tikz 绘制

答案3

另一个pgfplots解决方案:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16,
            x=1cm, y=1cm,      % global defined image features, instead "\def"
            ticklabel style={rounded corners=4pt, fill=white, inner xsep=1pt,
                             font=\small\sffamily},
            xmin=-1.5,xmax=1.5, 
            ymin=-3.5,ymax=3.5, 
            set layers = axis on top,
             }


\begin{document}
    \begin{tikzpicture}
\begin{axis}[
axis lines = middle,
xtick=\empty, extra x ticks={-1,0,1},
ytick=\empty,
xlabel = $x$,
ylabel = $y$,
samples at ={-1,-0.998,...,-0.5,-0.4,...,0.5,0.5002,0.5004,...,1}
             ]
\addplot [blue, very thick]  {0.5*(ln((1+x)/(1-x)))};
%
\addplot [dashed] coordinates {(-1,-3.5) (-1,3.5) };
\addplot [dashed] coordinates {( 1,-3.5) ( 1,3.5) };
%
\draw[<->,semithick]  (-1.5,-1.5) -- (1.5,1.5) node[above, pos=0.1, sloped] {$\Delta$};
\end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容