# Finding the integral $\int\frac{e^{x}}{e^{2x}+1}$

This question has been puzzling me for a bit and I'd like an explanation for what I'm doing wrong as my answer doesn't coincide with the correct one.

Let's say we're asked to find:

$$\int \frac{e^{x}}{e^{2x}+1}\mathrm{d}x$$

The way I chose to solve this was factor out an $$e^{2x}$$ from the denominator and work my way from there. So what I get is:

$$\int \frac{e^{x}}{e^{2x}(1+1/e^{2x})}dx$$

This could be rewritten as:

$$\int \frac{1}{e^{x}(1+(1/e^{x})^2)}dx$$

If we let:

$$u = \frac{1}{e^x}$$ $$du = -e^{-x} dx$$ $$dx = -e^xdu$$

So, now we're at:

$$\int \frac{1}{e^{x}(1+u^2)}(-e^x)du$$

Cancelling out the $$e^x$$ and removing the minus sign outside of the integral gives us:

$$-\int \frac{1}{1+u^2}du$$

This leaves us with:

$$-\int \frac{1}{1+u^2}du = -\tan^{-1}(\frac{1}{e^x})+c$$

However, I know the answer is wrong because the correct one is $$\tan^{-1}(e^x) + c$$. Can someone please tell me where I screwed up? Many thanks in advance!

• You didn't screw up. Note that for $x>0$, $\arctan x+\arctan 1/x=\pi/2$. – Jean-Claude Arbaut Apr 28 at 19:18
• why not substituting $u=e^x$ directly from the beginning ? – zwim Apr 28 at 19:23
• It should jump out at you that you have $\int \frac{d(e^x)}{(e^x)^2 + 1}$ – MPW Apr 28 at 19:25

As Jean-Claude Arbaut said, you didn't screw up. We have the identity $$\tan^{-1}(\frac{1}{y})=\frac{\pi}{2}-\tan^{-1}(y).$$ So it follows that $$-\tan^{-1}(1/e^x)=\tan^{-1}(e^x)-\pi/2=\tan^{-1}(e^x)+c.$$

• So what @Jean-Claude Arbaut and yourself are saying is that both answers are acceptable based on the above identity? Are we assuming the c is -pi/2 here? I'm sorry if this a really dumb question, but I'm very rusty with integrals at the moment. – in123321 Apr 28 at 19:43
• @in123321 It's not uncommon to have two expressions (or more) for the same primitive, which (necessarily) differ only by a constant: $\int f(x)dx=F_1(x)+C=F_2(x)+C'$. Of course, it's not the same constant $C$. Both $F_1$ and $F_2$ are correct, and neither is "better". – Jean-Claude Arbaut Apr 28 at 19:45
• Excellent, that cleared it up. Thanks @Jean-Claude Arbaut and everyone else who answered. – in123321 Apr 28 at 19:51
• @in123321 By the way, there is another simple expression for your primitive: $\arctan(\tanh(x/2))$. – Jean-Claude Arbaut Apr 28 at 19:57

You have been messing a little with the signs. $$\int\frac{e^x\,dx}{e^{2x}+1}=\int\frac{d(e^x)}{(e^x)^2+1}=\arctan(e^x)+c.$$

If we directly take $$e^x=t$$ right at the beginning, we get: $$\int \frac{e^x}{e^{2x}+1} \mathrm{d}x$$ $$=\int \frac{\mathrm{d}t}{t^2+1}$$ $$=\tan^{-1}t+ \mathrm{C}$$ $$=\tan^{-1}(e^x)+\mathrm{C}$$

$$e^x=\tan z$$ $$\int \frac{e^{x}}{e^{2x}+1}dx$$ $$\int \frac{\sec^2 z}{\tan^2 z+1}dz$$ $$=z+c=\tan^{-1}e^x+c$$
• I think you wanted to write $\tan^{-1}(e^x)$ at the end. – Botond Apr 28 at 19:48
One of the best thing you can do with indefinite integrals is take the derivative of your result and check if it is the integrand function: $$\frac{\text{d}}{\text{d}x} \left[-\arctan \left (\frac{1}{e^x}\right)+c\right]=\frac{\text{d}}{\text{d}x} \left[-\arctan \left (e^{-x}\right)+c\right]=-\frac{1}{1+e^{-2x}}({-e^{-x}})=\frac{e^{-x}}{1+e^{-2x}}=$$ $$=\frac{\frac{1}{e^x}}{1+\frac{1}{e^{2x}}}=\frac{\frac{1}{e^x}}{\frac{e^{2x}+1}{e^{2x}}}=\frac{1}{\frac{e^{2x}+1}{\frac{1}{e^x}}}=\frac{e^{x}}{e^{2x}+1}$$ So your result is absolutely correct, no matter what (except for calculation mistakes).