# Tikz: how to plot arcsec and arccos?

It is easy to plot arctan and arccot, but got inverse sec and csc functions, It seems difficult. Can anyone do it?

-

## migrated from math.stackexchange.comJul 30 '14 at 4:47

This question came from our site for people studying math at any level and professionals in related fields.

Welcome to TeX.SX! Please show us the complete but minimal code of how you are plotting an arctan-function. Like this we will know, what packages you are using and we do not have to type everything in order to add one function. Thanks. – LaRiFaRi Jul 30 '14 at 6:37

Using the pgfplots package, which makes plotting with TikZ easy, something as simple as

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[domain = -1:1, samples = 500]
\addplot[color = red]  {asin(x)};
\addplot[color = blue] {acos(x)};
\end{axis}
\end{tikzpicture}
\end{document}


works nicely

Notice that you need to restrict the domain of the function to something sensible ([-1,1]) and to get a smooth curve to have enough samples (points calculated in the range used). Also notice that the PGF maths engine works in degrees: you could of course convert the y-axis to radians if required (the question does not specify this).

For e.g. inverse secant the obvious apporach is to use standard identities (see for example http://en.wikipedia.org/wiki/Arcsecant) and to again pick appropriate domains but in 'parts'. For example

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[samples = 500]
\addplot[domain = -10:-1, color = red] {acos(1/x)};
\addplot[domain = 1:10, color = red]   {acos(1/x)};
\end{axis}
\end{tikzpicture}
\end{document}


gives

which is a plot of the inverse secant function over a hopefully-useful range.

-
Thank you! Just hope one day we can plot directly by using tikz... – user145722 Jul 30 '14 at 10:05
@user145722 It's not unique to PGF that the end user is expected to use some identities to use more 'advanced' trigonometric functions based on more 'basic' ones (for example, my calculator will handle sine/cosine/tangent happily but not secant!). – Joseph Wright Jul 30 '14 at 11:44
We do have asec and acsc in LaTeX3's l3fp, since it wasn't too hard to add. – Bruno Le Floch Jul 31 '14 at 7:17
@BrunoLeFloch I'm sure we do :-) My point was that it's not anything like as much as a necessity as cos/sin/tan and the inverses. – Joseph Wright Jul 31 '14 at 7:19

This answer was prepared for you long time ago.

\documentclass[pstricks,border=0pt,12pt,dvipsnames]{standalone}
\usepackage{amsmath}
\usepackage{pst-plot}
\usepackage[nomessages]{fp}

\FPeval\XMin{0-5}
\FPeval\XMax{5}
\FPeval\YMin{0-pi/3}
\FPeval\YMax{pi}

\FPeval\XOL{0-1/3} % of DeltaX
\FPeval\XOR{1/3} % of DeltaX
\FPeval\YOB{0-1/3} % of DeltaY
\FPeval\YOT{1/3} % of DeltaY

\FPset\TrigLabelBase{3}
\FPeval\DeltaX{1}
\FPeval\DeltaY{pi/TrigLabelBase}

\FPeval\AxisL{XMin+DeltaX*XOL}
\FPeval\AxisR{XMax+DeltaX*XOR}
\FPeval\AxisB{YMin+DeltaY*YOB}
\FPeval\AxisT{YMax+DeltaY*YOT}

\newlength\Width\Width=12cm
\newlength\Height\Height=8cm

\newlength\llx\llx=-5pt
\newlength\urx\urx=15pt
\newlength\lly\lly=-5pt
\newlength\ury\ury=15pt

\psset
{
llx=\llx,
lly=\lly,
urx=\urx,
ury=\ury,
xtrigLabels=false,
ytrigLabels=true,
trigLabelBase=\TrigLabelBase,
labelFontSize=\scriptstyle,
xAxisLabel=$x$,
yAxisLabel=$y$,
algebraic,
plotpoints=500,
}

\def\f{acos(1/x)}
\def\g{acos(x)}

\begin{document}
\pslegend[lt]{%
\color{NavyBlue}\rule{12pt}{1pt} & \color{NavyBlue} $y=\sec^{-1} x$\\
\color{Red}\rule{12pt}{1pt} & \color{Red} $y=\cos^{-1} x$
}
\begin{psgraph}
[
dx=\DeltaX,
dy=\DeltaY,
linecolor=gray,
tickcolor=gray,
ticksize=-3pt 3pt,
axespos=top,
]{<->}(0,0)(\AxisL,\AxisB)(\AxisR,\AxisT){\dimexpr\Width-\urx+\llx}{!}%{\dimexpr\Height-\ury+\lly}
\psaxes
[
dx=\DeltaX,
dy=\DeltaY,
labels=none,
subticks=5,
tickwidth=.4pt,
subtickwidth=.2pt,
tickcolor=Red!30,
subtickcolor=ForestGreen!30,
xticksize=\YMin\space \YMax,
yticksize=\XMin\space \XMax,
subticksize=1,
](0,0)(\XMin,\YMin)(\XMax,\YMax)
\psplot[linecolor=NavyBlue]{-5}{-1}{\f}
\psplot[linecolor=NavyBlue]{1}{5}{\f}
\psplot[linecolor=Red]{-1}{1}{\g}
\end{psgraph}
\end{document}


## Documentation

No need to load pst-math as pst-plot has defined the following functions.

• sin, cos, tan, acos, asin are in radians
• log, ln
• ceiling, floor, truncate, round
• sqrt (square root)
• abs (absolute value)
• fact (factorial)
• Sum
• IfTE (case structure)
-
XOR, XOL, YOT, YOB are offsets which are multiple of DeltaX and DeltaY, respectively. They are important to make the axes look more exotic (IMHO). – kiss my armpit Jul 30 '14 at 14:49
Please, never use \sec^{-1} and \cos^{-1} since there are no inverses of these functions. As a mathematician, my heart is missing a beat every time I see something like that. You should use \arcsec and \arccos instead. Sorry for nitpicking, but I'm caring for my health ... ;-) – Thomas F. Sturm Jul 31 '14 at 6:36
@ThomasF.Sturm: But if we restrict its domain then the inverse is available. As a layman, I have no idea what \arcsec (and arccos) differs from \sec^{-1} (and \cos^{-1}), could you elaborate more? In my mind, they are just different in notation. Probably you are talking about reciprocal rather than inverse. :-) – kiss my armpit Jul 31 '14 at 6:42
Yes, if we restrict the domain, then there is an inverse. But restricting the inverse means creating a new function which differs from the old function by its domain of definition. That's why it's called arccos because it's defined as inverse of the restricted cos (not of cos defined on the set of real numbers which is the usual domain). I use to torture my students with that difference ;-) – Thomas F. Sturm Jul 31 '14 at 8:28
By chance, somebody stumbled over this point today, i.e. that sin has no inverse. See my answer tex.stackexchange.com/questions/194204/… – Thomas F. Sturm Aug 1 '14 at 6:47

Needs an up-to-date pst-math.pro (TL 2014) or replace ASEC(x) with ACOS(1/x) and ACSC(x) with ASIN(1/x)

\documentclass{article}
\usepackage{pst-plot,pst-math}
\begin{document}

\begin{pspicture}(-5,-2)(5,4)
\psaxes[ytrigLabels,trigLabelBase=2,dy=1.57]{->}(0,0)(-5,-2)(5,4)
\psset{linewidth=1.5pt,algebraic}
\psplot[linecolor=cyan,arrows=-*,algebraic]{-5}{-1}{ASEC(x)}
\psplot[linecolor=cyan,arrows=*-]{1}{5}{ASEC(x)}
\psplot[linecolor=magenta,arrows=-*]{-5}{-1}{ACSC(x)}
\psplot[linecolor=magenta,arrows=*-]{1}{5}{ACSC(x)}
\end{pspicture}

\end{document}


Run it with xelatex or latex->dvips->ps2pdf

-
Thanks, actually I am trying to not use dvips->ps2pdf, just use PDFLatex. Eps figures driving me crazy. So that why I am trying to use PDFLatex for everything. Tikz works well with PDFLatex – user145722 Jul 30 '14 at 10:12
As I already mentioned use xelatex it has some more advantages than pdflatex – Herbert Jul 30 '14 at 10:26