M/M/1 Queues : Exercises
Introduction
Example problems
Click on the problems to reveal the solution
Problem 1
In addition the jump rate matrix is going to have an infinite number of rows and columns as shown below: $$ \mathbf{Q} = \left( \begin{matrix} -\lambda & \lambda & 0 & 0 & 0 & \dots & 0 & 0 \\ \mu & -\lambda-\mu & \lambda & 0 & 0 & \dots & 0 & 0 \\ 0 & \mu & -\lambda-\mu & \lambda & 0 & \dots & 0 & 0 \\ \vdots & \vdots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ \end{matrix} \right) $$ Finding the stationary distribution is straightforward. To do so we need to find some non trivial $\pi$ that satisfies: $$ \pi \mathbf{Q} = 0 $$ In other words we are trying to find the row vector $\pi$ that satisfies the matrix equation below: $$ \left( \begin{matrix} \pi_0 & \pi_1 & \pi_2 \dots & \pi_N \end{matrix} \right) \left( \begin{matrix} -\lambda & \lambda & 0 & 0 & 0 & \dots & 0 & 0 \\ \mu & -\lambda-\mu & \lambda & 0 & 0 & \dots & 0 & 0 \\ 0 & \mu & -\lambda-\mu & \lambda & 0 & \dots & 0 & 0 \\ \vdots & \vdots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ \end{matrix} \right) = 0 $$ When this system of equations is multiplied out we find that: $$ \pi_0 = \frac{\mu}{\lambda} \pi_1 \qquad \mu \pi_2 = (\lambda + \mu ) \pi_1 - \lambda \pi_0 = ( \lambda + \mu ) \pi_1 - \mu \pi_1 = \lambda \pi_1 \qquad \rightarrow \qquad \pi_2 = \frac{\lambda}{\mu}\pi_1 $$ The equations above follow the simple pattern shown below: $$ \pi_{n+1} = \frac{\lambda}{\mu} \pi_{n-1} $$ We can thus solve this family of equations recursively and get to: $$ \pi_{n} = \left(\frac{\lambda}{\mu} \right)^n \pi_0 $$ We now use normalization to determine $\pi_0$ $$ 1 = \sum_{n=0}^\infty \left(\frac{\lambda}{\mu} \right)^n \pi_0 \qquad \rightarrow \qquad \pi_0 = 1 - \left(\frac{\lambda}{\mu}\right) $$ Notice that in this step we have used a well known result on the sum of the geometric series: $\sum_{k=0}^\infty a^k = \frac{1}{1-a}$.
In closing note that the question asks for the expected number of books in the shop. Given we have the result above for the stationary distribution this expectation is clearly: \[ \mathbb{E}(X) = \sum_{i=0}^\infty i \pi_i = \sum_{i=0}^\infty i \left(1 - \frac{\lambda}{\mu}\right)\left(\frac{\lambda}{\mu}\right)^i = \left(1 - \frac{\lambda}{\mu}\right) \sum_{i=0}^\infty i \left(\frac{\lambda}{\mu}\right)^i = \frac{ \frac{\lambda}{\mu} }{1-\frac{\lambda}{\mu}} \] The result asked for in the question is obtained by multiplying top and bottom by $\mu$.
Problem 2
and the transition graph in the previous problem. The number of states in the transition graph for this problem is finite, whereas the number of states in the previous problem was infinite. The fact that we have only a finite number of states in this case also introduces differences in the jump rate matrix as shown below: $$ \mathbf{Q} = \left( \begin{matrix} -\lambda & \lambda & 0 & 0 & 0 & \dots & 0 & 0 \\ \mu & -\lambda-\mu & \lambda & 0 & 0 & \dots & 0 & 0 \\ 0 & \mu & -\lambda-\mu & \lambda & 0 & \dots & 0 & 0 \\ \vdots & \vdots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ 0 & 0 & 0 & 0 & 0 & \dots & \mu & -\mu \end{matrix} \right) $$ This jump rate matrix for this problem is an $n \times n$ matrix, whereas the jump rate matrix in the previous question had an infinite number of rows and an infinite number of columns.
Having focussed on the differences the process of finding the stationary distribution is relatively similar. As in question one we are looking for some non trivial $\pi$ that satisfies: $$ \pi \mathbf{Q} = 0 $$ In other words we are trying to find the row vector $\pi$ that satisfies the matrix equation below: $$ \left( \begin{matrix} \pi_0 & \pi_1 & \pi_2 \dots & \pi_N \end{matrix} \right) \left( \begin{matrix} -\lambda & \lambda & 0 & 0 & 0 & \dots & 0 & 0 \\ \mu & -\lambda-\mu & \lambda & 0 & 0 & \dots & 0 & 0 \\ 0 & \mu & -\lambda-\mu & \lambda & 0 & \dots & 0 & 0 \\ \vdots & \vdots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ 0 & 0 & 0 & 0 & 0 & \dots & \mu & -\mu \end{matrix} \right) = 0 $$ When this system of equations is multiplied out we find that: $$ \pi_0 = \frac{\mu}{\lambda} \pi_1 \qquad \lambda \pi_2 = (\lambda + \mu ) \pi_1 - \lambda \pi_0 = ( \lambda + \mu ) \pi_1 - \mu \pi_1 = \mu \pi_1 \qquad \rightarrow \qquad \pi_2 = \frac{\lambda}{\mu}\pi_1 $$ The equations above follow the simple pattern shown below: $$ \pi_{n+1} = \frac{\lambda}{\mu} \pi_{n-1} $$ We can thus solve this family of equations recursively and get to: $$ \pi_{n} = \left(\frac{\lambda}{\mu} \right)^n \pi_0 $$ We then use the normalization condition to determine $\pi_0$ $$ 1 = \sum_{n=0}^C\left(\frac{\lambda}{\mu} \right)^n \pi_0 \qquad \rightarrow \qquad \pi_0 = \frac{ 1 - \frac{\lambda}{\mu} }{1 - \left(\frac{\lambda}{\mu}\right)^{C+1} } $$ Notice that in this step there is again a difference between what is done here and what was done for a queue that does not have finite capacity. Obviously, if we only only have $(C+1)$ states $\pi$ has only $(C+1)$ elements and thus the sum above has a finite number of terms. We thus have to replace the result on the geometric series that we used in the previous case with the equally well-known result for the sum of the first $(C+1)$ terms in the gemetric series $\sum_{k=0}^C a^k = \frac{1 - a^{C+1}}{1-a}$.
In closing note that the questions asks for the expected level of energy in the batteries. Given we have the result above for the stationary distribution this expectation is clearly: $$ \mathbb{E}(X) = \sum_{n=0}^C n \pi_n = \frac{ 1 - \frac{\lambda}{\mu} }{ 1 - \left( \frac{\lambda}{\mu} \right)^{C+1}} \sum_{n=0}^C n \left( \frac{\lambda}{\mu} \right)^n $$