Question on indefinite integrals I have to integrate:
$$I_2 = \int \frac{e^{2x} - e^{x} + 1}{(e^x\cos(x) - \sin(x))\cdot \left(e^x\sin(x) + \cos(x)\right)} \text{d}x$$ 
I simply can't understand from where to begin with. Please help me in solving this problem.
 A: I consulted Moor and he suggested an approach involving differentiating the denominator.
Let $f(x) = (e^x \cos (x) - \sin(x))$ and $g(x) = (e^x \sin x + \cos x)$.  Then, note that, by the product rule $(fg)'=f'g +g'f = (e^x\cos(x)-e^x\sin(x) - \cos(x))(e^x \sin (x) + \cos (x)) + (e^x\sin (x) + e^x \cos(x)-\sin(x))(e^x \cos(x) - \sin(x))$ 
but this doesn't cancel out nicely to get $e^{2x}-e^x+1$.  In fact, expanding gives
$$(fg)' = (e^{2x} \sin(x) \cos(x) + e^x \cos^2(x) - e^{2x} \sin^2 (x) - \cos^2(x) - 2e^x \sin(x)\cos(x)) \\
+(e^{2x}\sin(x)\cos(x) - e^x \sin^2(x) + e^{2x} \cos^2 (x) + \sin^2(x) - 2e^x \sin (x) \cos (x))$$
Note that $fg'$ will cancel with a lot of $f'g$ terms if $fg'$ is negative.  In particular, note that $f'(x)g(x) - f(x)g'(x) = -(e^{2x} - e^x + 1)$.
So, our integral looks like
\begin{align*}
\int \frac{e^{2x} - e^{x} + 1}{(e^x\cos(x) - \sin(x))\cdot \left(e^x\sin(x) + \cos(x)\right)} \, dx &=
-\int \frac{f'(x)g(x) - f(x)g'(x)}{f(x)g(x)}\,dx \\
&= - \int \left(\frac{f'(x)}{f(x)} - \frac{g'(x)}{g(x)} \right) \,dx \\
&= - \ln(f(x)) + \ln(g(x)) + C \\
&= \ln\left(\frac{g(x)}{f(x)}\right) + C \\
&= \ln\left(\frac{e^x \sin(x) + \cos(x)}{e^x \cos(x) - \sin(x)} \right) +C
\end{align*}
A: HINT:
$$\int\space\frac{e^{2x}-e^x+1}{\left(e^x\cos(x)-\sin(x)\right)\left(e^x\sin(x)+\cos(x)\right)}\space\text{d}x=$$
$$2\int\space\frac{-e^x+e^{2x}+1}{e^{2x}\sin(2x)-\sin(2x)+2e^x\cos(2x)}\space\text{d}x=$$
$$2\int\space\frac{2\cosh(x)-1}{2\left(\cos(2x)+\sin(2x)\sinh(x)\right)}\space\text{d}x=$$
$$\frac{2}{2}\int\space\frac{2\cosh(x)-1}{\cos(2x)+\sin(2x)\sinh(x)}\space\text{d}x=$$
$$\int\space\frac{2\cosh(x)-1}{\cos(2x)+\sin(2x)\sinh(x)}\space\text{d}x=$$
$$2\int\space\frac{2\cosh(x)-\frac{1}{2}}{\cos(2x)+\sin(2x)\sinh(x)}\space\text{d}x=$$
$$2\int\space\left(\frac{\cosh(x)}{\cos(2x)+\sin(2x)\sinh(x)}-\frac{1}{2\left(\cos(2x)+\sin(2x)\sinh(x)\right)}\right)\space\text{d}x=$$
$$2\int\space\frac{\cosh(x)}{\cos(2x)+\sin(2x)\sinh(x)}\space\text{d}x-2\int\frac{1}{2\left(\cos(2x)+\sin(2x)\sinh(x)\right)}\space\text{d}x=$$
$$2\int\space\frac{\cosh(x)}{\cos(2x)+\sin(2x)\sinh(x)}\space\text{d}x-\int\frac{1}{\cos(2x)+\sin(2x)\sinh(x)}\space\text{d}x$$
A: I don't know a general method for this types of integrals, but if they will give a simple result, it must more or less be done in the following way:
We note that
$$
D(e^x\cos x-\sin x)=e^x(\cos x-\sin x)-\cos x
$$
and
$$
D(e^x\sin x+\cos x)=e^x(\cos x+\sin x)-\sin x.
$$
Next, our aim will be to do a kind of partial fraction decomposition (it is not a rational function, so it should perhaps be called something different),
$$
\frac{e^{2x}-e^x+1}{(e^x\cos x-\sin x)(e^x\sin x+\cos x)}=\frac{f(x)}{e^x\cos x-\sin x}+\frac{g(x)}{e^x\sin x+\cos x}.
$$
If we are really lucky $f(x)$ will be the derivative of $e^x\cos x-\sin x$ and $g(x)$ will be the derivative of $e^x\sin x+\cos x$. Now, as it happens, this is not exactly true. But almost! I encourage you to write
$$
a\frac{e^x(\cos x-\sin x)-\cos x}{e^x\cos x-\sin x}+b\frac{e^x(\cos x+\sin x)-\sin x}{e^x\sin x+\cos x}
$$
on common denominator, and try to find constants $a$ and $b$ so that it equals the original integrand. With that done, the integration will be simple, since it is of the form $a\phi'(x)/\phi(x)+b\psi'(x)/\psi(x)$ and thus giving logarithms. I leave those details to you. Scroll over below to see the final result.

 One gets $a=-1$ and $b=1$, and thus the final result is $$-\ln|e^x\cos x-\sin x|+\ln|e^x\sin x+\cos x|+C$$

A: I have a better solution to your problem
Here it goes:
\begin{aligned}
& \int \frac{e^{2 x}-e^{x}+1}{\left(e^{x} \sin x+\cos x\right)\left(e^{x} \cos x-\sin x\right)} dx \\
=& \int \frac{e^{2 x}-e^{x}+1}{\left(e^{2 x}+1\right) \sin \left(x+\tan ^{-1} \frac{1}{e^{x}}\right) \cdot \cos \left(x+\tan ^{-1} \frac{1}{e^{x}}\right)} d x \\
=&2 \int \frac{e^{2 x}-e^{x}+1}{\left(e^{2 x}+1\right) \sin \left(2 x+2 \operatorname{ta}^{-1}\left(\frac{1}{e^{x}}\right)\right)} d x \\
=&2 \int \frac{e^{2 x}-e^{x}+1}{\left(e^{2 x}+1\right) \sin \left(2 x+2 \cot ^{-1}\left(e^{x}\right)\right)} dx \\=&\int \operatorname{cosec}t~ dt=\ln \left|\tan \frac{t}{2}\right|+c \end{aligned}
where $t=2 x+2 \cot ^{-1}\left(e^{x}\right)$. Note that
$$\frac{d t}{d x}=2-\frac{2}{1+e^{2 x}} \cdot e^{x}=\frac{2\left(e^{2 x}-e^{x}+1\right)}{e^{2 x}+1}$$
Also, $\frac{t}{2}=x+\tan ^{-1}\left(\frac{1}{e^{x}}\right)$ so we have $$
\tan \frac{t}{2}=\frac{\tan x+\frac{1}{e^{x}}}{1-\frac{t x}{e^{x}}} =\frac{e^{x} \sin x+\cos x}{e^{x} \cos x-\sin x}$$
Thus the integral is $$ \boxed{\ln \left|\frac{e^{x} \sin x+\cos x}{e^{x} \cos x-\sin x}\right|+c} $$
