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.

$\endgroup$
  • $\begingroup$ My guess is that you missed something in getting from $1+e^x$ to $1+e^{-x}$ because you later have $\frac{1}{1+e^x} = \frac{e^x}{1+e^x}$... $\endgroup$ – El'endia Starman Oct 2 '11 at 2:55
  • 2
    $\begingroup$ As a sidenote, this problem is a special case of math.stackexchange.com/questions/60045/… (but the core question here is different). $\endgroup$ – anon Oct 2 '11 at 3:02
  • $\begingroup$ @El'endia: No, he has $\frac1{1+e^{-x}}\left(\frac{e^x}{e^x}\right)=\frac{e^x}{1+e^x}$, after using symmetry to replace the original integrand by $\frac1{1+e^{-x}}$. $\endgroup$ – Brian M. Scott Oct 2 '11 at 3:05
  • $\begingroup$ A direct route to the Wolfram solution is via the substitution $u=1+e^x$, $du=e^x dx=(u-1)dx$, followed by integration of $\frac1{u(u-1)}$ by partial fractions. Your solution is nicer, though. $\endgroup$ – Brian M. Scott Oct 2 '11 at 3:08
  • $\begingroup$ @Brian: I meant that he started with $\frac{dx}{1+e^x}$ and after using symmetry and multiplying by 1, got $\frac{e^x}{1+e^x} dx$. That just doesn't seem right... o.O? Of course, I have to mention that I have no idea what this symmetry mentioned is and that I was wrong in the first place. :P $\endgroup$ – El'endia Starman Oct 2 '11 at 3:11
15
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – Greg Martin Oct 2 '11 at 19:37
5
$\begingroup$

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*}$$

$\endgroup$
4
$\begingroup$

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) $

$\endgroup$
2
$\begingroup$

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. $$

$\endgroup$
2
$\begingroup$

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*}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.