2
$\begingroup$

I wish to integrate $\int_{-a}^a \frac{dx}{1+e^x}.$ By symmetry, the above is equal to $\int_{-a}^a \frac{dx}{1+e^{-x}}$ Now multiply by $e^x/e^x$ to get $\int_{-a}^a \frac{e^x}{1+e^x} dx$ which integrates to $\log(1+e^x) |^a_{-a} = \log((1+e^a)/(1+e^{-a})),$ which is not correct. According to Wolfram, we should get $2a + \log((1+e^{-a})/(1+e^a)).$ Where is the mistake?

EDIT: Mistake found: was using log on calculator, which is base 10.

  • 0
    @Brian: Ah, I see now.2011-10-02

5 Answers 5

16

All of these answers are correct, but there is a more correct answer: $ \int_{-a}^a \frac{dx}{1+e^x} = a. $ (You should check that $\log((1+e^a)/(1+e^{-a})) = \log(e^a) = a$....) And you've basically found the proof already: set $ I_1 = \int_{-a}^a \frac{dx}{1+e^x} \text{ and } I_2 = \int_{-a}^a \frac{e^x\, dx}{1+e^x}. $ Then $I_1=I_2$ as you saw, but also $ I_1 + I_2 = \int_{-a}^a \bigg( \frac{1}{1+e^x} + \frac{e^x}{1+e^x} \bigg) \,dx = \int_{-a}^a 1\,dx = 2a. $ Therefore $I_1=I_2=a$. "anon" commented to this effect on the original question.

  • 1
    Or, vamping on Neil G.'s answer: the difference between the integrand $f(x) = 1/(1+e^x)$ and the function $g(x) = 1/2$ is the _odd_ function $1/(1+e^x)-1/2 = (1-e^x)/2(1+e^x)$, and therefore the integral of $f$ over any symmetric interval $[-a,a]$ is the same as the integral of $g$ over that interval.2011-10-02
5

Both answers are equal. Split your answer into $\log(1+e^a)-\log(1+e^{-a})$, and write this as $\begin{align*}\log(e^a(1+e^{-a}))-\log(e^{-a}(1+e^a))&=\log e^a+\log(1+e^{-a})-\log e^{-a}-\log(1+e^a)\\ &=2a+\log((1+e^{-a})/(1+e^a))\end{align*}$

4

Your solution is absolutely correct. $\log(\frac{1+e^a}{1+e^{-a}})=2a+\log(\frac{1+e^{-a}}{1+e^a})$

The authors might have arrived at the solution like this. Let $I_1=\int^{a}_{-a} \frac{1}{1+e^x}dx$ and $I_2=\int^{a}_{-a} \frac{e^x}{1+e^x}dx$

Adding $I_1$ and $I_2$ , $I_1+I_2=\int^{a}_{-a}dx=2a$ As you have calculated $I_2=\log\left(\frac{1+e^a}{1+e^{-a}}\right)$

Therefore $I_1=2a-I_2=2a-\log\left(\frac{1+e^a}{1+e^{-a}}\right)=2a+\log\left(\frac{1+e^{-a}}{1+e^{a}}\right) $

2

Another way to solve this is to notice that

$f(x) = \frac{1}{1+e^{-x}}$

is the logistic sigmoid, which is the conversion from log-odds to probability. So,

$f(x) + f(-x) = 1$

Then, $ \int_{-a}^a f(x)dx=\int_0^a (f(x) + f(-x))dx=a. $

2

Another way to evaluate this integral is by substitution. In fact, let $u=e^x$. Then \begin{eqnarray*} \int\frac{1}{1+e^x}dx&=&\int\frac{1}{u(u+1)}du=\int\left(\frac{1}{u}-\frac{1}{u+1}\right)du\\ &=&\ln u-\ln(u+1)+C=x-\ln(e^x+1)+C \end{eqnarray*}