3

I would like to plot the function arcsin(sin(x)) within an axis environment using PGFplots. The behaviour I obtain leads me to believe that the functions arcsin and sin cancel each other before anything else to produce the function x -> x, which is not exactly the proper behaviour.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}[line cap=round,line join=round,x=1cm,y=1cm]
        \begin{axis}[
        x=1cm,y=1cm,
        axis lines=middle,
        ymajorgrids=true,
        xmajorgrids=true,
        xmin=-8.5,
        xmax=8.5,
        ymin=-6.5,
        ymax=7.5,
        xtick={-10,-9,...,10},
        ytick={-7,-6,...,7},
        ]
            \addplot[smooth,samples=100,domain=-8.5:8.5] (\x,{asin(sin(\x))});
        \end{axis}
    \end{tikzpicture}
\end{document}

This produces the following output: Output of the given code.

However, the output should be the following: enter image description here

How to solve this? I am especially looking for a way avoiding to break the function on so many subintervals, as this can become extremely tedious.

1
  • 4
    Welcome to TeX.SE. Maybe you get degrees but need radians?
    – mickep
    Apr 25 at 6:18

1 Answer 1

5

As said by @mickeo, you need convert x to deg first for sin function and then convert back the radian after the asin function.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
x=1cm,y=1cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-8.5,
xmax=8.5,
ymin=-6.5,
ymax=7.5,
]
\addplot[green!50!black,very thick,smooth,samples=100,domain=-8.5:8.5] {asin(sin(deg(x)))*(pi/180)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    We could probably get sharper corners here if we plotted on a scale where the input values included exactly pi/2. I'm not sure how to do that, but it might be easier if instead of using deg(x), we plotted arcsin(sin(x))*(pi/180) on a domain of -487:487 or so (since 487 degrees is about 8.5 radians) and then rescaled the horizontal axis. Apr 25 at 17:29
  • @MishaLavrov I think if we want both x axis and y axis in radian. We better stick with the -8.5 to 8.5 range. To sharpen the curve we could use higher samples (e.g., samples=1000).
    – Tom
    Apr 26 at 3:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .