# How to draw this function with tikz $\frac12 \ln(\frac{x+1}{1-x})$?

My problem is it is defined on ]-1,1[ so I don't know how to write the domaine

\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}


i want to get something like this

• You can use \def\Xmin{-0.99} \def\Xmax{0.99}  and then \draw [domain=\Xmin:\Xmax,thick,red]. But, like yesterday, it might be a better idea to use pgfplots for this. – Marijn Mar 23 at 14:31

Here's a solution using pgfplots:

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

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


Function y = 1/2 * ln((x + 1) / (x - 1)) approaches to infinity when x approaches to 1 or -1. Moreover, this function is undefined at both x = 1 and x = -1. Hence, you can only plot this function in the range (-1 + delta, 1 - delta), where delta is a small positive value. Therefore,

• The plot domain is changed to [-1 + \Xshift, 1 - \Xshift] where \Xshift is a small positive number.
• To imitate the drawing range, y-range is changed to [-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}


• it is not like the picture the axes are small then the graph how to ameliorate this please ? – linda Oiladali Mar 23 at 14:44
• Maybe add \draw [domain=\Xmin+0.1:0,thick,red] plot (\x,{((1/2) (ln((1+\x)/(1-\x)))) }); just before the plots. – user194703 Mar 23 at 14:45
• what is Xshift ? – linda Oiladali Mar 23 at 14:47
• @lindaOiladali See the updated answer. – muzimuzhi Z Mar 23 at 15:06
• Please how to draw x=1 and x=-1 ? – linda Oiladali Mar 23 at 15:51

Another pgfplots solution:

\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 [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}


• please @Zarko if I want to draw a function defined on $]-\infty,-1[\cup]1,+\infty[$ how to change ? – linda Oiladali Mar 23 at 20:46
• @lindaOiladali, well form -\infty to +\infty, is not possible, you need infinity wide paper ;-). Seriously, are you sure, that your function exist outside domain -1:1 ? – Zarko Mar 23 at 21:10
• no @zarko not this function, an other one $\frac12\ln(\frac{x+1}{x-1})$ – linda Oiladali Mar 23 at 21:14
• @lindaOiladali, but diagram show this function! In principle it is possible, if function exist. You only need accordingly to change in my answer to given function optimizet secting samplin points with for example \domain=-10:10, samples=2001 and change \xmin and \xmyx accordingly. However, about this would be better to ask new question for your new particular case and consider, that this your question is answered. So you only need to accept (by clicking on check mark at top left side of selected answer) from gotten answers the one, which you the most liked :-) – Zarko Mar 23 at 21:25