I have the following 2 questions to integrate as part of my practice.
(i) $\displaystyle \int\frac1{x(x+2)}dx$
(ii) $\displaystyle \int\frac1{e^x+2}dx$
and I have tried it myself but I am not getting the answer required
(i) $\displaystyle \frac12\ln x-\frac12\ln(x+2)+C$
(ii) $\displaystyle \frac12x-\frac12\ln(e^x+2)+C$
Below are my workings
(i) $\displaystyle \int\frac1{x(x+2)}dx\;=\;\int\frac1{x^2+2x}dx\;=\;\frac{\ln(x^2+2x)}{2x+2} +C$
(ii) $\displaystyle \int\frac1{e^x+2}dx\;=\frac{\ln(e^x+2)}{e^x} +C$
May I know what am I doing wrong such that my answer differs?
For i):
With the constant rule 'trick', what you are effectively doing is: $$\int \frac{1}{x^2+2x} \ dx$$
When $u = x^2+2x, du = 2x+2 \ dx, dx = \frac{du}{2x+2}$, we have:
$$\int \frac{1}{u(2x+2)} \ du, $$
and since you cannot get the $2x+2$ part to be in terms of $u$, this 'trick' does not work.
What you can do is to use partial fractions: $$\frac{A}{x} + \frac{B}{x+2} = \frac{1}{x(x+2)}$$ $$A(x+2) + Bx = 1 \tag{1}\label{eq1}$$ $$(A+B)x + 2A = 1 \tag{2}\label{eq2}$$
This is an identity – it will hold for any $x$. So when $x = 0, A = \frac{1}{2}$ from equation $2$, and when $x = -2$, $B = -\frac{1}{2}$ from equation $1$.
Can you integrate it now?