Probability of measuring a particle in the ground state: having trouble with the integration I am working on a problem in the context of an infinite symmetric potential barrier around the origin, with barriers at $x=- \frac{a}{2}$ and $x=\frac{a}{2}$. The wave function is a symmetric triangle-function:

$$
\Psi (x) = \begin{cases} 0 &amp; x &lt; - \frac{a}{2} \\ \sqrt{\frac{12}{a^3}} \left( \frac{a}{2} - \lvert x \rvert \right) &amp; -\frac{a}{2} \leq x \leq \frac{a}{2} \\ 0 &amp; x &gt; \frac{a}{2} \end{cases}
$$

I must calculate the probability of measuring a particle in the above eigenstate in the ground state (when $n=1$). The way to attack this problem is to calculate the coefficient $c_1$, and then square it. Here follows my (wrong) attempt.

$$
c_n = \int\limits_{-\infty}^{\infty} \psi_n^*(x)\Psi (x)\,\mathrm dx
$$

I understand from the above expression that the $\psi_n^* (x)$ is just the "regular" solution to the particle in a box. Given this symmetric potential, and that $n=1$ (odd $n$, even function), I must set

$$
\psi _1^* (x) = \sqrt{\frac{2}{a}} \cos\frac{\pi x}{a}
$$

The expression for $c_n$ becomes

$$
c_n = \int\limits_{-a/2}^{a/2}  \sqrt{\frac{2}{a}} \cos\frac{\pi x}{a} \sqrt{\frac{12}{a^3}} \left( \frac{a}{2} - \lvert x \rvert \right)\,\mathrm dx \\
$$

Simplifying gives

$$
c_n = \frac{2 \sqrt{6}}{a^2} \int\limits_{-a/2}^{a/2} \cos \left( \frac{\pi x}{a} \right) \left( \frac{a}{2} - \lvert x \rvert \right)\,\mathrm dx
$$

This can be solved by partial integration, setting $u'=\cos \left( \frac{\pi x}{a} \right)$ and $v= \left( \frac{a}{2} - \lvert x \rvert \right)$. Hence, $u=\frac{a}{\pi}\sin \left( \frac{\pi x}{a} \right) $ and $v'=-1$. The integral itself then becomes

$$
\int\limits_{-a/2}^{a/2} \cos \left( \frac{\pi x}{a} \right) \left( \frac{a}{2} - \lvert x \rvert \right)\,\mathrm dx = \frac{a}{\pi}\sin \left( \frac{\pi x}{a} \right)\left( \frac{a}{2} - \lvert x \rvert \right) - \int \frac{a}{\pi}\sin \left( \frac{\pi x}{a} \right) (-1)\,\mathrm dx
$$

Cleaning up

$$
\mbox{Integral} = \frac{a^2}{2 \pi} \sin \left( \frac{\pi x}{a} \right) - \lvert x \rvert \frac{a}{\pi} \sin \left( \frac{\pi x}{a} \right) - \frac{a^2}{\pi ^2} \cos \left( \frac{\pi x}{a} \right)
$$

Now we just need to insert the limits. However, we see quite easily from the above expression that upon inserting $x=\pm \frac{a}{2}$, the last term vanishes, since $\cos ( \pm\pi / 2 = 0)$. The sine terms will equal $1$ when the limit is positive and $-1$ when the limit is negative. Hence, we are left with

$$
\mbox{Integral} = \left[ \frac{a^2}{2 \pi} - \frac{a}{2} \frac{a}{\pi} \right] - \left[ \frac{a^2}{2 \pi}(-1) - \lvert \frac{-a}{2} \rvert \frac{a}{\pi}(-1)  \right] = \frac{a^2}{2 \pi} + \frac{a^2}{2 \pi} = \frac{a^2}{\pi}
$$

Plugging this into the original expression

$$
c_n = \frac{2 \sqrt{6}}{a^2} \cdot \frac{a^2}{\pi} = \frac{2 \sqrt{6}}{\pi} \approx 1.56
$$

So, you see the problem. My $c_n$ is larger than one, which will give me a rather un-physical probability. Am I wrong in this derivation in my assumption for $\psi _n^* (x)$? If not, then where?

Wolfram Alpha gives me that 

$$
\mbox{Integral} = \frac{2a^2}{\pi ^2} \\
\Rightarrow c_1 = \frac{2 \sqrt{6}}{a^2} \cdot \frac{2a^2}{\pi ^2} = \frac{4 \sqrt{6}}{\pi ^2}
$$

Using this gives me a probability of $c_1^2 \approx 0.986$, which at least has physical meaning. Also, logic tells me that there is a very high probability of finding the particle in the ground state, so this further backs up WA's answer.
I think your tactics using partial integration from the start is the problem because $\lvert x \rvert$ is not differentiable at $x=0$ so working with its derivative is not quite kosher (and $v' = -1$ is certainly wrong since for $x &lt; 0$ the gradient of $-\lvert x \rvert$ is $1$).

I suggest you go about it step by step:

\begin{align}
  c_1 &amp;= \frac{2 \sqrt{6}}{a^2} \int\limits_{-a/2}^{a/2} \cos \left( \frac{\pi x}{a} \right) \left( \frac{a}{2} - \lvert x \rvert \right) dx \\
      &amp;= \frac{2 \sqrt{6}}{a^2} \biggl( \frac{a}{2} \underbrace{\int\limits_{-a/2}^{a/2} \cos \left( \frac{\pi x}{a} \right) dx}_{ = \, I_{1} } - \underbrace{\int\limits_{-a/2}^{a/2} \lvert x \rvert \cos \left( \frac{\pi x}{a} \right) dx}_{ = \, I_{2} } \biggr)
\end{align}

Now, integral $I_1$ is easy:

\begin{align}
  I_{1} &amp;= \int\limits_{-a/2}^{a/2} \cos \left( \frac{\pi x}{a} \right) dx \\
   &amp;= \left[ \frac{a}{\pi} \sin \left( \frac{\pi x}{a} \right)  \right]_{-a/2}^{a/2} = \frac{a}{\pi} \sin \left( \frac{\pi}{2} \right) + \frac{a}{\pi} \sin \left( \frac{\pi}{2} \right) = \frac{2a}{\pi}
\end{align}

For integral $I_2$ I suggest that you use that 

\begin{equation}
 \lvert x \rvert = \begin{cases} x &amp;  x \geq 0 \\ -x &amp; x \leq 0 \end{cases}
\end{equation}

and split up the integral into two integrals

\begin{align}
  I_{2} &amp;= \int\limits_{-a/2}^{a/2} \lvert x \rvert \cos \left( \frac{\pi x}{a} \right) dx \\
   &amp;= \int\limits_{0}^{a/2} x \cos \left( \frac{\pi x}{a} \right) dx - \int\limits_{-a/2}^{0} x \cos \left( \frac{\pi x}{a} \right) dx
\end{align}

Now use integration by parts with $u'=\cos \left( \frac{\pi x}{a} \right)$ ($\Rightarrow u=\frac{a}{\pi}\sin \left( \frac{\pi x}{a} \right) $) and $v= x$ ($\Rightarrow v'= 1 $) to solve the integral 

\begin{align}
  \int x \cos \left( \frac{\pi x}{a} \right) dx &amp;= \frac{a}{\pi} x \sin \left( \frac{\pi x}{a} \right) - \int \frac{a}{\pi}\sin \left( \frac{\pi x}{a} \right) dx \\
  &amp;= \frac{a}{\pi} x \sin \left( \frac{\pi x}{a} \right) + \frac{a^2}{\pi^2} \cos \left( \frac{\pi x}{a} \right) \ ,
\end{align}

so

\begin{align}
  I_{2} &amp;= \int\limits_{0}^{a/2} x \cos \left( \frac{\pi x}{a} \right) dx - \int\limits_{-a/2}^{0} x \cos \left( \frac{\pi x}{a} \right) dx \\
        &amp;= \left[ \frac{a}{\pi} x \sin \left( \frac{\pi x}{a} \right) + \frac{a^2}{\pi^2} \cos \left( \frac{\pi x}{a} \right) \right]_{0}^{a/2} - \left[ \frac{a}{\pi} x \sin \left( \frac{\pi x}{a} \right) + \frac{a^2}{\pi^2} \cos \left( \frac{\pi x}{a} \right) \right]_{-a/2}^{0} \\
        &amp;= \frac{a^2}{2 \pi} - \frac{a^2}{\pi^2} - \frac{a^2}{\pi^2} + \frac{a^2}{2 \pi} = \frac{a^2}{\pi} - \frac{2 a^2}{\pi^2}
\end{align}

Plugging this into the equation for $c_1$ gives

\begin{align}
  c_1 &amp;= \frac{2 \sqrt{6}}{a^2} \left( \frac{a}{2} I_{1} - I_{2} \right) \\
      &amp;= \frac{2 \sqrt{6}}{a^2} \left( \frac{a^{2}}{\pi} - \frac{a^2}{\pi} + \frac{2 a^2}{\pi^2} \right) \\
      &amp;= \frac{4 \sqrt{6}}{\pi^2}
\end{align}

and that is indeed what Wolfram Alpha gives you.