Q:

Problem using trigonometric substitution: Domain of $\theta$

I'm studying calculus from Rogawski's Calculus. In trigonometric substitution $x=a\sec \theta$ he made a note:

In the substitution $x = a \sec θ$ , we choose $0\le  θ \le π$
2 if $x \ge a$ and $π \le θ < \frac{3π}2$ if
$x \le −a$. With these choices, $a \tan \theta$ is the
positive square root $\sqrt{x^2 − a^2}$.

When I work on the integral:
$$\int \frac {\mathrm{d}x}{x\sqrt{x^2-9}}$$
Using the substitution of $x=3\sec\theta$ with the domain of $\theta$ shown above, the integration will be :
$$\int \frac {dx}{x\sqrt{x^2-9}}= \int \frac {3\sec\theta\tan\theta d\theta}{(3\sec\theta)\sqrt{9\sec^2-9}}=\int \frac {\tan\theta d\theta}{3\sqrt{\tan^2 \theta}}$$
$$= \int \frac{d\theta}{3}= \frac\theta 3+ \mathrm{C}$$
$$\int \frac {dx}{x\sqrt{x^2-9}}= \frac 13 \sec^{-1}\left(\frac x3\right)+ \mathrm{C}$$
Which is very wrong in the negative part of the domain of $x$ as shown in this graph:

Notice that the slope of the blue function in the negative domain should be positive not negative!.
The problem of this substitution is $2$ things:
$1)$ The domain of $\theta$ is chosen so that inverse cannot be done, since $\theta =\sec^{-1}x\notin  (\pi,\frac{3\pi}2) $ which is  the domain chosen for $\theta $.
$2)$ Depending on first problem, we should choose $\theta \in (0,\pi)-\{\frac\pi 2\}$ which makes $\sqrt{\tan^2 \theta}=|\tan \theta|$. The integral then should be re-written as a piecewise function:
$$\int \frac {dx}{x\sqrt{x^2-9}}= \int \frac {3\sec\theta\tan\theta d\theta}{(3\sec\theta)\sqrt{9\sec^2-9}}$$
$$\int \frac {\tan\theta d\theta}{3\sqrt{\tan^2 \theta}} = \begin{cases} = \int \frac {d\theta}{3} = \frac 13 \sec^{-1}(\frac x3)+ C & \text{if $\theta \in (0,\frac \pi 2)$} \equiv x>3 \\= \int \frac {-d\theta}{3} = \frac {-1}3 \sec^{-1}(\frac x3)+ C & \text{if $\theta \in (\frac \pi 2,\pi)$}\equiv x<-3 \end{cases}$$
My questions are:
Is this thinking right ? there is mistake to choose the domain of $\theta$ as mentioned in the book ?
Mathematica gives me the answer of $-\dfrac {1}{3} \tan^{-1} \left(\dfrac{3}{\sqrt{x^2-9}}\right) +\mathrm{C}$ which is right when graphed. But how to construct this integral ?
Thanks for help.

A:

To get to the answer Mathematica gives, you can let$$  u = \sqrt{x^2 -9}.$$  You should get $$ \frac{1}{3} \arctan \left( \frac{\sqrt{x^2-9}}{3} \right) + \text{constant} $$ and use the fact that $$\arctan(\frac{1}{x}) = \frac{\pi}{2} - \arctan(x)~~~,x\gt 0$$ and 
$$\arctan(\frac{1}{x}) = -\frac{\pi}{2} - \arctan(x)~~~,x\lt 0 $$

A:

In the substitution $x = a \sec\theta$ , we choose $0 \leq \theta < \frac\pi2$ if $x \geq a$ and $\pi \leq \theta < \frac{3\pi}2$ if
  $x \leq −a$. With these choices, $a \tan\theta$ is the
  positive square root $\sqrt{x^2 − a^2}$.

I think what Rogawski may have in mind here is that $x = a \sec\theta$
is not quite the same thing as $\theta = \sec^{-1}\left( \frac xa \right)$.
Since $\sec (-\theta) = \sec\theta$, the possible solutions
for $x = a \sec\theta$ are:
$$\theta = \sec^{-1}\left( \frac xa \right) + 2n\pi \quad \text{or} \quad
\theta = -\sec^{-1}\left( \frac xa \right) + 2n\pi, 
\quad \text{where $n \in \mathbb Z$.}$$
If $x \geq a > 0$, 
so that Rogawski's advice is to let $0 \leq \theta < \frac\pi2$,
then $\frac xa \geq 1$ and the "positive" solution with $n = 0$ 
produces a value of $\theta$ in the correct interval:
$$0 \leq \theta = \sec^{-1}\left( \frac xa \right) < \frac\pi2.$$
But keep in mind that the range of $\sec^{-1}$
is $\left[0, \frac\pi2\right) \cup \left(\frac\pi2, \pi\right]$.
If $x \leq -a < 0$,
so that Rogawski's advice gives $\pi \leq \theta < \frac{3\pi}2$,
then $\frac xa \leq -1$ and the "positive" solution with $n=0$
can give only values of $\theta$ in the interval $\left(\frac\pi2, \pi\right]$,
not $\left[\pi, \frac{3\pi}2\right)$.
And any other value of $n$ produces a value of theta even farther from
the desired interval.
The only way to produce a value in the desired interval,
$\left[\pi, \frac{3\pi}2\right)$,
is to take the "negative" solution with $n = 1$:
$$\pi \leq \theta = -\sec^{-1}\left( \frac xa \right) + 2\pi < \frac{3\pi}2,$$
which you can verify after observing that in this case (with $\frac xa < -1$),
$-\pi \leq -\sec^{-1}\left( \frac xa \right) < -\frac\pi2$.
So the correct subsitution (and reverse substitution) is
$$\int \frac {dx}{x\sqrt{x^2-9}} 
= \int \frac {d\theta}{3} = \frac \theta 3 + C
= \begin{cases}
  \dfrac13 \sec^{-1}\left( \dfrac x3 \right) + C & \text{if }\ x \geq 3, \\
 -\dfrac13 \sec^{-1}\left( \dfrac x3 \right) + C & \text{if }\ x < -3.
\end{cases}$$
(Note that the constant $2\pi$ in the "negative" case is incorporated
in the constant of integration, $C$.)
This is the same result you got by setting
$\theta \in \left[0, \frac\pi2\right) \cup \left(\frac\pi2, \pi\right]$
and using the fact that $\sqrt{\tan^2 \theta} = |\tan\theta\,|$.
Personally, I see nothing wrong with your method;
in fact it may be easier to keep track of the need to do a "sign change"
for the integral when $x \leq -3$ when you have an explicit invocation
of the absolute value function, $|\tan\theta\,|$,
rather than rules that implicitly change the sign of $\sec^{-1}\theta$
(that is, the requirement that $\pi \leq \theta < \frac{3\pi}2$,
whose application seems a bit obscure to me).
In short, both methods give the same result, which is the correct result,
but only if applied exactly as required at every step.
Your method seems less prone to error than the method Rogawski
recommends, so everything considered, I think I prefer yours.
(Of course if you are currently taking a class in calculus and
have to write solutions of integrals like this on homework or exams,
it's a good policy to write your solution in a way that will be
easy for the grader to grade correctly. So if you use a technique not
shown in class or in the textbook, make sure you explain it clearly,
like the way you explained that $\sqrt{\tan^2 \theta} = |\tan\theta\,|$.
It just makes life easier for everyone in the end.)

