I am struggling with how to correctly plot functions $f(x,a)$ involving trigonometric and inverse trigonometric functions. Here $x$ denotes the independent variable and $a$ is a parameter. In general, $f(x,a)$ is too complicated to be evaluated analytically, so I am forced to evaluate it numerically.
The problem can be illustrated with the following simplified function:
$f(x,a)=\frac{1}{ax}\sin^{-1}(a\sin x)-1$
where $-\pi \leq x \leq \pi$ and $a$ is a parameter. The problem is best illustrated for the special case $a=1$,
$f(x,1)=\frac{1}{x}\sin^{-1}(\sin x)-1$.
Please bear in mind that this is a twice-simplified case (simpler function and special case $a=1$) and that I have to plot more complicated functions by evaluating them numerically. So I am looking for a way to plot $f(x,1)$ numerically.
Now the problem I am struggling with is that $f(x,1)=0$ identically, but numerically this is not the case because $\sin^{-1} x$ always returns a value between $0$ and $\pi/2$. The consequence is that for values $x>\pi/2$ I do not get $f(x,1)=0$.
How can I deal with this problem? The only way I have come up with so far is to check whether $x>\pi/2$ and if that is the case, I make sure that to adjust the value returned by $\sin^{-1}$ to lie in the range $\pi/2$ to $\pi$. Seems easy enough. But it's not clear to me how to extend this treatment to the case where $a\ne 1$ and how to extend this treatment to more complicated cases like
$f(x,a)=\frac{1}{ax}\tan^{-1}(\frac{a\sin x}{a \cos x - a + 1})-1$
If I plot $\sin(x)$ and $\arcsin(x)$ for $[-\pi,\pi]$ I get:
So the expected $\arcsin(\sin(x)) = x$ will only work for $x \in [-\pi/2, \pi/2]$, because outside your $\arcsin$ is not the inverse function.
For $x \in (\pi/2, \pi]$ you should use translations like $$ f(x) = \pi/2 + \arccos(x) $$
The blue curve labeled $g$ is $\sin(x)$ for $x \in [\pi/2, \pi]$. The black curve labeled $h$ is $\pi/2 + \arccos(\sin(x))$ for $x \in [\pi/2, \pi]$.