Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the context of information theory, entropy is a measure of uncertainty of a random variable. In quantum mechanics, the uncertainty principle states that $\Delta x\Delta k \ge 1/2$. The same can be expressed in terms of information entropy as $S_x + S_k \ge 1 + \ln\pi$. The information entropy $S_x$ is defined as:

$$ S_x = \int_{-\infty}^{\infty} {\rho(x) \ln\rho(x) dx} $$

where $\rho(x)$ is the probability density function of the variable $x$.

In continuation[1,2,3] of my study of the infinite square well problem, I'd like to check whether the informational version of uncertainty principle holds. For that, I need to calculate $S_x$ and $S_k$, for various numbers of $n=1,2,3,\ldots$, and check if their sum is bounded, knowing the respective probability density functions for position $x$ and momentum $k$.

Here is my code for $S_x$:

(* The length of the well *)
L = 1;

(* The eigenfunctions, n=1,2,3,... u[n,x] is zero outside of [0,L] *)
u[n_, x_] := Sqrt[2/L] Sin[n π x/L]

(* Probability density function for the x(=particle position) variable *)
(* Again, the domain of ρ(n,x) is the [0,L] interval *)
ρ[n_, x_] := u[n, x]\[Conjugate] u[n, x]

integrand = 
 Simplify[-ρ[n, x] Log[ρ[n, x]], 
  n ∈ Integers && x ∈ Reals]

(* Out= -2 Log[2 Sin[n π x]^2] Sin[n π x]^2 *)

(* Integrate over [0,L] since we haven't defined u[n,x] outside of [0,L] *)
(* We could have defined it though and then we would be integrating from -inf to +inf *)
Integrate[integrand, {x, 0, L}]

(* Out= -(1/(6 n π))(π (6 n - I π + 6 I n^2 π + n Log[64] - 
      12 n Log[1 - E^(2 I n π)] + 6 n Log[Sin[n π]^2]) + 
   6 I PolyLog[2, E^(2 I n π)] - 
   3 (-1 + Log[2 Sin[n π]^2]) Sin[2 n π]) *)

At this point it's already obvious that the value of the integral cannot be determined, since the terms $\sin(n\pi)$ equal zero and $\ln{0}$ is undefined.

FullSimplify[%, n ∈ Integers]

During evaluation of In[72]:= FullSimplify::infd: Expression Log[1-E^(2 I n [Pi])] simplified to -[Infinity]. >>

During evaluation of In[72]:= FullSimplify::infd: Expression Log[Sin[n [Pi]]^2] simplified to -[Infinity]. >>

During evaluation of In[72]:= FullSimplify::infd: Expression Log[2 Sin[n [Pi]]^2] simplified to -[Infinity]. >>

During evaluation of In[72]:= General::stop: Further output of FullSimplify::infd will be suppressed during this calculation. >>

Out[72]= Indeterminate

My book says that $S_x = \ln(2L) - 1$. Any ideas on how to trick Mathematica to calculate the integral ?

Mathematica.SE related (to the physical problem) questions:

Is there a more mathematica-y way to label these plots?

Why does FourierTransform converge while same integral manually written does not?

Calculate integral for arbitrary parameter n in infinite square well problem

share|improve this question
I commented out the Out= lines so that it's easier to copy-and-paste your code. – Rahul Nov 10 '13 at 20:50
Thanks @RahulNarain for taking care of that! – Zet Nov 10 '13 at 20:50
up vote 3 down vote accepted

I managed to teach Mathematica calculate the integral for arbitrary $n$, with a little aid:

$$\int_0^L\rho(n,x)\ln(\rho(n,x))dx = (2/L)\int_{0}^{L}\sin^2(n\pi x/L)\ln\left[(2/L)\sin^2(n\pi x/L)\right]dx$$

Mathematica has trouble, apparently, handling all the parameters $(n,L,x)$, so I resort to the following substitution: $n\pi x/L=u \Rightarrow (n\pi/L) dx = du$ and the new limits of integration are: $ 0 \rightarrow 0, L \rightarrow n\pi$.

Thus, now, the integral becomes:

$$\begin{align} \int_0^L\rho(n,x)\ln(\rho(n,x))dx &= (2/L) \int_0^{n\pi}\sin^2 u\ln\left[(2/L)\sin^2 u\right]\frac{L}{n\pi}du\\ &= \left(\frac{2}{n\pi}\right)\int_0^{n\pi}\sin^2 u\ln\left[(2/L)\sin^2 u\right]du \end{align}$$

The function $\sin^2 u\ln[(2/L)\sin^2 u$ is periodic with a period $T=\pi$:

f[u_] := Sin[u]^2 Log[(2/L) Sin[u]^2]
f[u + π] == f[u]
(* Out= True *)

As it can also be seen from its plot:

Plot[-Sin[u]^2 Log[Sin[u]^2], {u, 0, 4 Pi}, Filling -> Axis]

enter image description here


$$\begin{align} \int_0^L\rho(n,x)\ln(\rho(n,x))dx &= \left(\frac{2}{n\pi}\right)n \int_0^{\pi}\sin^2(u)\ln\left[(2/L)\sin^2 u\right]du \\ &= (2/\pi)\int_0^{\pi}\sin^2{u}\ln\left[(2/L)\sin^2 u\right]du \end{align}$$

-(2/π) Integrate[Sin[u]^2 Log[(2/L) Sin[u]^2], {u, 0, π}, 
  Assumptions -> L > 0]
(* Out= -1 + Log[2] + Log[L] *)
share|improve this answer
By the way, how could I get rid of those tiny integral symbols? Is there anything like \bigint or something ? – Zet Nov 11 '13 at 19:26
If you put the math in display mode with $$…$$ instead of $…$, the integral signs will be full-sized. You'll probably want to use align for the multiline equations then. See and – Rahul Nov 11 '13 at 19:34

Here's a way to approach this by defining a function for each $n$, which you can then do separately.

L = 1;
u[n_, x_] := Sqrt[2/L] Sin[n π x/L];
ρ[n_, x_] := u[n, x]\[Conjugate] u[n, x];
integrand[n_, x_] := Simplify[-ρ[n, x] Log[ρ[n, x]], n ∈ Integers && x ∈ Reals]

Now calculate the desired integral:

Integrate[integrand[1, x], {x, 0, L}]
-1 + Log[2]

The $n=2$ and $n=3$ cases gives the same answer.

share|improve this answer
Thanks @bills. I was hoping to get M calculate it for any arbitrary n. But if impossible, then I will accept it. – Zet Nov 10 '13 at 19:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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