# Pi and Bouncing Balls

I recently re-watched a Sixty Symbols video in which the wonderful Ed Copeland describes the unexpected appearance of $\pi$ in a problem about bouncing balls.

The set-up is as follows: consider two masses $m_1$ and $m_2$ moving in one dimension on a smooth, horizontal surface. The bigger mass $m_1$ approaches the smaller mass $m_2$ at speed $u.$ The two masses collide; the smaller mass recoils, bounces off a wall behind it, and moves back towards the bigger mass. The two collide again, and again, and again; every time, the bigger mass slows down a little as the smaller mass drums against it. Eventually the bigger mass will stop, having had all of its energy stolen by the smaller mass.

Here’s the interesting result: if the two masses are related by the equation

$m_1=16\times 100^N m_2\quad\text{for}\quad N\in\mathbb{N}_0,$

the number of collisions undergone by the two balls before the bigger mass changes direction spells out the first $(N+1)$ digits of $\pi$.

So if the bigger mass is 16 times greater than the smaller mass, there will be 3 collisions before the bigger mass turns around; if the bigger mass is 1 600 times greater than the smaller mass, there will be 31 collisions, and so on.

The goal of this post is to provide a derivation of this result, relying heavily on the use of 2×2 matrices. I’ll do my best to omit all the algebraic manipulation that doesn’t need to be seen. I hope you’ll follow me all the way!

$\$

The first objective is to find an expression for the velocities of the two masses after their $n$th collision.

We’ll first introduce some notation. The symbol $u_i^n$ represents the velocity of the body with mass $m_i$ immediately before the $n$th collision, and the symbol $v_i^n$ is its velocity immediately after the $n$th collision.

We assume that each collision obeys the conservation of linear momentum and of kinetic energy, which gives us the two equations

$m_1 u_1^n+m_2 u_2^n=m_1 v_1^n+m_2 v_2^n$

$\frac{1}{2}m_1 (u_1^n)^2+\frac{1}{2}m_2 (u_2^n)^2=\frac{1}{2}m_1 (v_1^n)^2+\frac{1}{2}m_2 (v_2^n)^2$

Solving this pair of simultaneous equations for $v_1^n$ and $v_2^n$ is a bit boring, so I’ll just quote the results:

$\displaystyle v_1^n=\frac{(m_1 - m_2)u_1^n + 2m_2 u_2^n}{m_1+m_2}$

$\displaystyle v_2^n=\frac{2m_1 u_1^n+(m_2-m_1)u_2^n}{m_1+m_2}$

We can summarise this information by introducing the ratio $x$, defined by

$\displaystyle x=\frac{m_1}{m_2},$

and writing the simplified equations in matrix form:

$\displaystyle \binom{v_1^n}{v_2^n}=\frac{1}{x+1}\left(\begin{matrix} x-1 & 2 \\ 2x & 1-x\end{matrix}\right)\binom{u_1^n}{u_2^n}$

Next, we have to relate the velocities before the $n$th collision to the velocities after the $(n-1)$th collision. The bigger mass’ velocity doesn’t change between collisions, so

$v_1^{n-1}=u_1^n$

but the smaller mass bounces (elastically) off a wall, so its velocity changes sign:

$v_2^{n-1}=-u_2^n$

Again, we can write this in matrix form:

$\displaystyle \binom{u_1^n}{u_2^n}=\left(\begin{matrix} 1 & 0 \\ 0 & -1\end{matrix}\right)\binom{v_1^{n-1}}{v_2^{n-1}}$

Substituting this expression into the other matrix equation above gives

$\displaystyle \binom{v_1^n}{v_2^n}=\frac{1}{x+1}\left(\begin{matrix} x-1 & 2 \\ 2x & 1-x\end{matrix}\right)\left(\begin{matrix} 1 & 0 \\ 0 & -1\end{matrix}\right)\binom{v_1^{n-1}}{v_2^{n-1}}$

By the rules of matrix multiplication, this is equivalent to

$\displaystyle \binom{v_1^n}{v_2^n}=\frac{1}{x+1}\left(\begin{matrix} x-1 & 2 \\ -2x & x-1 \end{matrix}\right)\binom{v_1^{n-1}}{v_2^{n-1}}$

This recursive equation allows us to work out the velocities of the two masses after the $n$th collision in terms of their initial velocities:

$\displaystyle \binom{v_1^n}{v_2^n}=\frac{1}{x+1}\left(\begin{matrix} x-1 & 2 \\ -2 & x-1\end{matrix}\right)\frac{1}{x+1}\left(\begin{matrix} x-1 & 2 \\ -2 & x-1\end{matrix}\right)...\frac{1}{x+1}\left(\begin{matrix} x-1 & 2 \\ -2 & x-1\end{matrix}\right)\binom{u}{0}$

$\displaystyle \binom{v_1^n}{v_2^n}=\frac{1}{(x+1)^n}\left(\begin{matrix} x-1 & 2 \\ -2x & x-1\end{matrix}\right)^n\binom{u}{0}$

$\$

Finding the expression for a matrix raised to a power is in general difficult, unless we find a clever way of rewriting it.

Let’s give the matrix above a name:

$\displaystyle M=\left(\begin{matrix} x-1 & 2 \\ -2x & x-1\end{matrix}\right)$

Now suppose we can write the matrix $M$ in the form

$M=SDS^{-1}$

where $S$ is some matrix, $S^{-1}$ is its inverse, defined such that

$\displaystyle SS^{-1}=S^{-1}S=I=\left(\begin{matrix} 1 & 0 \\ 0 & 1\end{matrix}\right)$

and the filling of the sandwich $D$ is a diagonal matrix, one of the form

$\displaystyle D=\left(\begin{matrix} \lambda_1 & 0 \\ 0 & \lambda_2\end{matrix}\right)$

If we can write $M$ in this form, then

$M^n=(SDS^{-1})^n$

$M^n=(SDS^{-1})(SDS^{-1})(SDS^{-1})...(SDS^{-1})$

$M^n=SD(S^{-1}S)D(S^{-1}S)D(S^{-1}S)...(S^{-1}S)DS^{-1}$

$M^n=SDIDIDI...IDS^{-1}$

$M^n=SD^n S^{-1}$

Since $D$ is a diagonal matrix, the evaluation of $D^n$ is not complicated by funny cross-terms:

$\displaystyle D^n=\left(\begin{matrix} \lambda_1 & 0 \\ 0 & \lambda_2 \end{matrix}\right)^n=\left(\begin{matrix} \lambda_1^n & 0 \\ 0 & \lambda_2^n \end{matrix}\right)$

This would allow us to find an explicit expression for $M^n$. This technique is known as matrix diagonalisation.

But how do we find expressions for both $S$ and $D$? Since

$M=SDS^{-1},$

we can let $S$ act on the right-hand side, giving

$MS=SDS^{-1}S$

$MS=SD$

Let’s write $S$ in the form

$S=(\begin{matrix}\bold{v}_1 & \bold{v}_2\end{matrix})$

where the $\bold{v}_i$ are two-component column vectors. Then

$M(\begin{matrix}\bold{v}_1 & \bold{v}_2\end{matrix})=(\begin{matrix}\bold{v}_1 & \bold{v}_2\end{matrix})\left(\begin{matrix} \lambda_1^n & 0 \\ 0 & \lambda_2^n\end{matrix}\right)$

$\displaystyle (\begin{matrix} M\bold{v}_1 & M\bold{v}_2\end{matrix})=(\begin{matrix} \lambda_1 \bold{v}_1 & \lambda_2 \bold{v}_2 \end{matrix})$

By equating the components it must be true that

$M\bold{v}_1=\lambda_1\bold{v}_1$

$M\bold{v}_2=\lambda_2\bold{v}_2$

The vectors $\bold{v}_i$ that satisfy this equation are said to be the eigenvectors of $M$, and the $\lambda_i$ are their corresponding eigenvalues. So the matrix $S$ is the matrix whose columns are the eigenvectors of $M$, and $D$ is the diagonal matrix whose non-zero elements are the eigenvalues of $M$.

$\$

How do we find the eigenvalues and eigenvectors of a matrix? We could always guess them simultaneously, but this is difficult in general. Fortunately there’s an algorithm we can use to work out the eigenvalues of a matrix, using the following reasoning: the eigenvalues of $M$ satisfy the equation

$M\bold{v}_i=\lambda_i\bold{v}_i$

We are free to insert an identity matrix $I$ into the right-hand side:

$M\bold{v}_i=\lambda_i I\bold{v}_i$

$(M-\lambda_i I)\bold{v}_i=\bold{0}$

This equation can in principle be solved by applying the inverse of $M-\lambda_i I$ to both sides, giving

$(M-\lambda_i I)^{-1}(M-\lambda_i I)\bold{v}_i=(M-\lambda_i I)^{-1}\bold{0};$

$\bold{v}_i=\bold{0},$

but this is not the case we’re interested in; we want non-zero eigenvectors! If the inverse of the matrix $M-\lambda _i I$ exists, we will be stuck with this $\bold{v}_i=0$ solution. We therefore conclude that for $\bold{v}_i\ne 0$, the inverse of $M-\lambda_i I$ does not exist.

If a matrix has no inverse, its determinant, defined through

$\text{det}\left(\begin{matrix} a & b \\ c & d \end{matrix}\right)=ad-bc,$

is equal to zero. So the eigenvalues of $M$ satisfy the equation

$\text{det}(M-\lambda_i I)=0$

$((x-1)-\lambda_i)^2+4x=0$

This is the so-called characteristic equation. Its solutions are

$\lambda_i=(x-1)\pm 2i\sqrt{x}$

We’ll label these two solutions with a plus or minus subscript, such that

$\lambda_+=(x-1)+2i\sqrt{x}$

$\lambda_-=(x-1)-2i\sqrt{x}$

This gives us the elements of the diagonal matrix $D$. We also need the eigenvectors $\bold{v}_i$ that correspond to these eigenvalues, which by definition satisfy

$\displaystyle \left(\begin{matrix} x-1 & 2 \\ -2x & x-1 \end{matrix}\right)\bold{v}_i=\lambda_i\bold{v}_i$

We find the two eigenvectors are

$\displaystyle \bold{v}_+=\binom{1}{i\sqrt{x}}$

$\displaystyle \bold{v}_-=\binom{1}{-i\sqrt{x}}$

Hence our two matrices $S$ and $D$ are

$\displaystyle S=\left(\begin{matrix} 1 & 1 \\ i\sqrt{x} & -i\sqrt{x} \end{matrix}\right)$

$\displaystyle D=\left(\begin{matrix} (x-1)+2i\sqrt{x} & 0 \\ 0 & (x-1)-2i\sqrt{x} \end{matrix}\right)$

The last bit of work to do is to find the inverse of the matrix $S$. I’ll just write down the answer:

$\displaystyle S^{-1}=\frac{1}{2\sqrt{x}}\left(\begin{matrix} \sqrt{x} & -i \\ \sqrt{x} & i \end{matrix}\right)$

$\$

Let’s substitute these results into our  expression for the velocities of the masses:

$\displaystyle \binom{v_1^n}{v_2^n}=\frac{1}{(x+1)^n}M^n\binom{u}{0}$

$\displaystyle \binom{v_1^n}{v_2^n}\frac{1}{(x+1)^n}SD^n S^{-1}\binom{u}{0}$

$\displaystyle \binom{v_1^n}{v_2^n}=\frac{1}{(x+1)^n}\left(\begin{matrix} 1 & 1 \\ i\sqrt{x} & -i\sqrt{x} \end{matrix}\right)\left(\begin{matrix} \lambda_+^n & 0 \\ 0 & \lambda_-^n \end{matrix}\right)\frac{1}{2\sqrt{x}}\left(\begin{matrix} \sqrt{x} & -i \\ \sqrt{x} & i \end{matrix}\right)\binom{u}{0}$

After lots of matrix multiplication, we are left with the result

$\displaystyle \binom{v_1^n}{v_2^n}=\frac{1}{2}\frac{1}{(x+1)^n}\binom{\lambda_+^n + \lambda_-^n}{i\sqrt{x}\lambda_+^n - i\sqrt{x}\lambda_-^n}\,u$

Hence

$\displaystyle v_1^n=\frac{u}{2(x+1)^n}(\lambda_+^n+\lambda_-^n)$

We’re very close! We just need to simplify this equation using the expressions

$\lambda_{\pm}=(x-1)\pm 2i\sqrt{x}$

Raising a complex number to a power in Cartesian form is not easy, so we’ll convert to polar form instead:

$\displaystyle \lambda_{\pm}=\sqrt{(x-1)^2+(2\sqrt{x})^2}\,e^{i\arctan\left(\pm\frac{2\sqrt{x}}{x-1}\right)}$

$\displaystyle \lambda_{\pm}=(x+1)\,e^{\pm i\arctan\left(\frac{2\sqrt{x}}{x-1}\right)}$

Substituting this expression into that for $v_1^n$ gives

$\displaystyle v_1^n=\frac{u}{2(x+1)^n}\left(\left[(x+1)e^{i\arctan\left(\frac{2\sqrt{x}}{x-1}\right)}\right]^n+\left[(x+1)e^{-i\arctan\left(\frac{2\sqrt{x}}{x-1}\right)}\right]^n\right)$

$\displaystyle v_1^n=\frac{u}{2(x+1)^n}\left((x+1)^n e^{in\arctan\left(\frac{2\sqrt{x}}{x-1}\right)}+(x+1)^n e^{-in\arctan\left(\frac{2\sqrt{x}}{x-1}\right)}\right)$

$\displaystyle v_1^n=\frac{u}{2}\left(e^{in\arctan\left(\frac{2\sqrt{x}}{x-1}\right)}+e^{-in\arctan\left(\frac{2\sqrt{x}}{x-1}\right)}\right)$

Now the awesome bit:

$\displaystyle \cos\theta=\frac{1}{2}(e^{i\theta}+e^{-i\theta}),$

hence

$\displaystyle v_1^n=\cos\left(n\arctan\left(\frac{2\sqrt{x}}{x-1}\right)\right)\,u$

So the velocity of the larger mass varies with the cosine of the number of collisions it has suffered. Nice!

$\$

Now we ask the question: after how many collisions is the velocity of the greater mass $m_1$ negative? That is, after how many collisions is the bigger mass guaranteed to have changed direction? Since cosine goes to 0 when its argument reaches $\frac{\pi}{2}$, $n$ must satisfy the equation

$\displaystyle n\arctan\left(\frac{2\sqrt{x}}{x-1}\right)>\frac{\pi}{2}$

$\displaystyle n>\frac{\pi}{2\arctan\left(\frac{2\sqrt{x}}{x-1}\right)}$

Take the special relation quoted in the video:

$m_1=16\times 100^N m_2$

$x=16\times 100^N$

Then

$\displaystyle n>\frac{\pi}{2\arctan\left(\frac{2\sqrt{16\times 100^N}}{16\times 100^N - 1}\right)}$

For any $N\ge 0$,

$16\times 100^N-1\approx 16\times 100^N,$

so we can write

$\displaystyle n>\frac{\pi}{2\arctan\left(\frac{2\times 4\times 100^{\frac{N}{2}}}{16\times 100^N}\right)}$

$\displaystyle n>\frac{\pi}{2\arctan\left(\frac{1}{2\times 100^{\frac{N}{2}}}\right)}$

$\displaystyle n>\frac{\pi}{2\arctan\left(\frac{1}{2\times 10^N}\right)}$

The last step: we can use the Taylor expansion of the arctangent function to say that

$\arctan x\approx x\quad\text{for}\quad |x|\ll 1$

Hence

$\displaystyle n>\frac{\pi}{2\frac{1}{2\times 10^N}}$

$n>10^N\pi$

If $n$ satisfies this inequality, the velocity of the larger mass is negative, ie it has collided with the smaller mass sufficiently many times that its direction has been reversed. For example, if $N=0$,

$n>3.14159...$

This means the bigger mass acquires a negative velocity at $n$=4, so the number of collisions that occur before this happens is 3.

Let’s try a bigger number. If $N=2$,

$n>314.15927...$

This means the bigger mass acquires a negative velocity at $n$=315, so the number of collisions that occur before this happens is 314.

Hence in general, the number of collisions that occur before the one which causes the big mass to change direction is the greatest integer that fails to satisfy the inequality above, written

$n(N)=\lfloor 10^N\pi\rfloor$

where the brackets represent the floor function.

$\$

Here’re some animations simulating the encounter. This first animation shows the case where the bigger mass is 16 times greater than the smaller mass.

The number of collisions after which the velocity of the greater mass is still positive is counted (in unary!) in the top-left. As predicted, there are 3 such collisions.

Here’s the case where the bigger mass is 1 600 times greater than the smaller mass.

The larger mass is much harder to turn around this time. This is because the big mass can only impart a finite amount of energy to the smaller mass each collision, so more collisions are needed to stop the big mass. Notice how rapidly the small mass moves when the large mass is stationary – all of the kinetic energy initially possessed by the big mass is concentrated into the small mass. Since the (classical) kinetic energy of an object is given by

$E=\frac{1}{2}mv^2$

and the large mass is 1 600 times heavier than the small mass, the small mass must move 40 times faster than the big mass does initially if energy is conserved! This is faster than the screen capture software can keep up with, which is why the small mass’ motion looks a little strange in the animation.

As predicted, there are 31 collisions before the big mass is made to turn around.

$\$

Unfortunately, this derivation doesn’t provide an intuition as to why $\pi$ should appear. It’s worth emphasising that it has nothing to do with the shape of the two masses, which were pictured as circular by accident.

The appearance of $\pi$ stems from the appearance of the cosine function; the appearance of the cosine stems from the symmetry of the eigenvalues of $M$; the symmetry of $M$‘s eigenvalues stems from its own symmetry; and the symmetry of the matrix $M$ stems from the conservation of momentum and energy. But this doesn’t answer the question “where is the hidden circle that’s making $\pi$ appear?”. Here’s an interesting post which addresses this question.