How to Plot Inverse Hyperbolic Functions in PGFPlots
At a glance
- 1. Use logarithm formulas
Write each inverse hyperbolic function in terms of ln and sqrt, which PGF's math parser can evaluate.
- 2. Declare plot functions
Use pgfmathdeclarefunction to give PGFPlots reusable names for the formulas.
- 3. Respect the domains
Plot arcosh only for x at least 1, and artanh only between negative 1 and 1.
- 4. Compile the example
Add the declarations before the axis environment, then call the functions in addplot expressions.
PGFPlots expressions do not need a special inverse-hyperbolic command: you can express these functions using natural logarithms and square roots, then declare them for use in plot expressions. This works for plotting and for other PGF math expressions.
The example below declares all three common inverse hyperbolic functions and plots them on domains where their values are real. Use arsinh, arcosh, and artanh as the function names; these names make clear that the commands are inverse functions, not reciprocals.
Formulas PGF can evaluate
The real-valued inverse hyperbolic functions can be written as
PGF’s math parser provides ln for the natural logarithm and sqrt for the square root. The real domains matter: arsinh accepts every real input, arcosh requires , and artanh requires . At the endpoints of artanh’s domain, the function diverges, so do not include or in the plotted interval.
Declare the functions
Put each declaration in the document preamble, after loading pgfplots (which loads TikZ):
\pgfmathdeclarefunction{arsinh}{1}{%
\pgfmathparse{ln((#1)+sqrt((#1)^2+1))}%
}
\pgfmathdeclarefunction{arcosh}{1}{%
\pgfmathparse{ln((#1)+sqrt((#1)^2-1))}%
}
\pgfmathdeclarefunction{artanh}{1}{%
\pgfmathparse{0.5*ln((1+(#1))/(1-(#1)))}%
}
The {1} says that each function takes one argument. Within the declaration, #1 stands for that argument. For example, arsinh(x) in a plot is evaluated by inserting the plot’s current x value into the formula.
Complete PGFPlots example
This minimal document plots all three functions. It uses a separate domain for each curve; the artanh interval stops short of its vertical asymptotes.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfmathdeclarefunction{arsinh}{1}{%
\pgfmathparse{ln((#1)+sqrt((#1)^2+1))}%
}
\pgfmathdeclarefunction{arcosh}{1}{%
\pgfmathparse{ln((#1)+sqrt((#1)^2-1))}%
}
\pgfmathdeclarefunction{artanh}{1}{%
\pgfmathparse{0.5*ln((1+(#1))/(1-(#1)))}%
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$},
ylabel={$y$},
xmin=-4, xmax=4,
ymin=-3, ymax=3,
legend pos=north west,
samples=150,
grid=both
]
\addplot[blue,domain=-4:4] {arsinh(x)};
\addlegendentry{$\operatorname{arsinh}(x)$}
\addplot[red,domain=1:4] {arcosh(x)};
\addlegendentry{$\operatorname{arcosh}(x)$}
\addplot[teal,domain=-0.95:0.95] {artanh(x)};
\addlegendentry{$\operatorname{artanh}(x)$}
\end{axis}
\end{tikzpicture}
\end{document}
The document needs the pgfplots package. compat=1.18 selects a defined PGFPlots compatibility level; use a level supported by your installed version if it is older. The domain option controls the x-values sampled for each curve. The y limits merely choose the visible part of the graph; they do not change the function.
Check a point by hand
For , the first two functions give
These provide useful checks on the plotted curves: arsinh passes through approximately , while arcosh starts at . For artanh, a convenient check is :
Common mistakes
- Using inverse notation as a reciprocal. The notation is often used for the inverse function, but can be mistaken for . The declared
arsinh(x)name avoids that ambiguity. - Plotting outside the real domain. The arcosh expression contains , which is not real for . The artanh expression has a logarithm that is undefined over the reals at and beyond its endpoints. Set a valid domain for each curve.
- Including artanh’s endpoints. Its values grow without bound as approaches or . Choose endpoints such as
-0.95:0.95for a finite plotted segment. - Expecting a built-in inverse command. Declaring the formulas avoids relying on whether a particular PGF/TikZ version recognizes a specific inverse-hyperbolic function name.
- Using the direct arsinh formula at extreme magnitudes. For ordinary plotting ranges it is convenient, but at very large negative inputs, can lose numerical precision through cancellation. If that matters, restrict the plot to a sensible range or use a numerically stable implementation suited to the calculation.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.