Indefinite integral of secant cubed $\int \sec^3 x\>dx$ I need to calculate the following indefinite integral:
$$I=\int \frac{1}{\cos^3(x)}dx$$
I know what the result is (from Mathematica):
$$I=\tanh^{-1}(\tan(x/2))+(1/2)\sec(x)\tan(x)$$
but I don't know how to integrate it myself. I have been trying some substitutions to no avail. 
Equivalently, I need to know how to compute:
$$I=\int \sqrt{1+z^2}dz$$
which follows after making the change of variables $z=\tan x$.

$\int  \sqrt (1 + x^2) dx$
let $x = \tan \theta $
then $dx = \sec ^2\theta  d\theta $
we have the integral is then:
$\int  \sec ^3\theta  d\theta $ 
recall:
$\tan ^2\theta  + 1 = \sec ^2\theta $
and write as:
$\int  \sec \theta (\sec ^2\theta )d\theta  $
continue with integration by parts,
by letting:
$u = \sec \theta $
and
$dv = \sec ^2\theta  d\theta $
we have:
$v = \tan \theta $
and
$du = \sec \theta \tan \theta  d\theta $  
and thus,
$uv - \int vdu$ 
is then:
$\sec \theta \tan \theta  - \int \sec \theta \tan ^2\theta  d\theta $
recall: 
$\tan ^2\theta  + 1 = \sec ^2\theta $
we have:
$\sec \theta \tan \theta  - \int \sec \theta (\sec ^2\theta  - 1) d\theta $
after distribution, altogether we have:
$\int \sec ^3\theta  d\theta  = \sec \theta \tan \theta  - \int \sec ^3\theta  d\theta  - \int \sec \theta  d\theta $
rearranging and collecting like-terms:
$2\int \sec ^3\theta  d\theta  = \sec \theta \tan \theta  - \int \sec \theta  d\theta $
$2\int \sec ^3\theta  d\theta  = \sec \theta \tan \theta  - \ln |\sec \theta  + \tan \theta |$
$\int \sec ^3\theta  d\theta  = (1/2)[\sec \theta \tan \theta  - \ln |\sec \theta  + \tan \theta |]$
+++++++++++++++++++++++++++
without u\sin g integration tables, we can derive 
$\int \sec \theta  d\theta $
..........
$=\int 1/\cos \theta  d\theta $
$=\int \cos \theta /\cos ^2\theta  d\theta $
$=\int \cos \theta /(1 - \sin ^2\theta ) d\theta $
let $u = \sin \theta $
then $du = \cos \theta  d\theta $
we have:
$\int 1/(1 - u^2) du$
partial fractions:
$A/(1 - u) + B/(1 + u) = 1$
$A + B = 1$
$A - B = 0$
$A = 1/2$
$B = 1/2$
we have:
$-(1/2)\ln |1 - u| + (1/2)\ln |1 + u|$
by rules of logarithms:
$(1/2)\ln |(1 + u)/(1 - u)|$
$(1/2)\ln |(1 - u^2)/(1 - u)^2|$
by rules of logarithms:
$\ln |\sqrt (1 - u^2)/(1 - u)|$
recall:
$u = \sin \theta $ 
$\ln |\sqrt (1 - \sin ^2\theta )/(1 - \sin \theta )|$
$\ln |\sqrt \cos ^2\theta /(1 - \sin \theta )|$
$\ln |\cos \theta /(1 - \sin \theta )|$
$\ln |\cos \theta (1 + \sin \theta )/(1 - \sin ^2\theta )|$
$\ln |\cos \theta (1 + \sin \theta )/\cos ^2\theta |$
$\ln |1/\cos \theta  + \sin \theta /\cos \theta |$
$\ln |\sec \theta  + \tan \theta |$
++++++++++++++++++++++++++++
but the integral of $\int \sec ^3\theta  d\theta $ is:
$\int \sec ^3\theta  d\theta  = (1/2)[\sec \theta \tan \theta  - \ln |\sec \theta  + \tan \theta |]$ + CONS\tan T
and \sin ce 
$\tan \theta  = x = x/1 =$ opposite/adjacent,
with the pythagorean theorem, we derive:
hypotenuse = $\sqrt (1 + x^2)$
and thus, $\sec \theta $ = hypotenuse/adjacent = $\sqrt (1 + x^2)$
$\int  \sqrt (1 + x^2) dx$
$= (1/2)[x\sqrt (1 + x^2) - \ln |\sqrt (1 + x^2) + x|]$ + CONS\tan T
