Filling of a tank - recurrence relation Suppose a tank has a maximum limit of 100 units. Each day 2,1 and 0 units are added to the water level with probability p,r and q. Any excess water would overflow and if it reaches the minimum level of 0 then it cannot be filled again.At the end of the day 1 unit is released from the tank. I tried to solve this the following way.
Let L be the random variable corresponding to the water level at the end of the day. $$Pr[L=k+1]=p, Pr[L=k]=r,Pr[L=k-1]=q$$
Let $q_k$ be the probability that the water level will become 0 if, at the beginning of the day the water level is k. Then,
$$q_k=pq_{k+1}+rq_k+qq_{k-1}$$
Solving this by difference equations I got the following general solution
$$q_k=A+B(q/p)^k$$
To determine A and B I need suitable boundary conditions. Should I use $q_{99}=0$ or $q_{100}=0$? I think the tank can never be at 100 water level at end of any day so $q_{99}=0$?Also the recurrence formula I have written for $q_k$, should it be for k values between 1 and 99 or 1 and 98? ANy help will be much appreciated.
 A: It can be written as a markov chain to obtain the probabilities. But there are 101 states and couldn't find a simple closed form like in the case of 
the original gambler's ruin.
If the limit was 5 units instead, the markov chain is written as:
\begin{align*}
  A &= \left(\begin{array}{rrrrrr}
r & q & 0 & 0 & 0 & p \\
p & r & q & 0 & 0 & 0 \\
0 & p & r & q & 0 & 0 \\
0 & 0 & p & r & q & 0 \\
0 & 0 & 0 & 0 & 1 & 0 \\
0 & 0 & 0 & 0 & 0 & 1
\end{array}\right)
\end{align*}
where the states are written in order $q_4,q_3,q_2,q_1,q_0,q_5$
and the probabilities of absorption can be found by computing $\left(I-Q\right)^{-1} \cdot R$ where
\begin{align*}
  I = \left(\begin{array}{rrrr}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1
\end{array}\right), 
  Q = \left(\begin{array}{rrrr}
r & q & 0 & 0 \\
p & r & q & 0 \\
0 & p & r & q \\
0 & 0 & p & r 
\end{array}\right),
R = \left(\begin{array}{rr}
0 & p \\
0 & 0 \\
0 & 0 \\
q & 0 \\
\end{array}\right)
\end{align*}
The same pattern can be extended to the limit of 100. 
For particular values of $p,q,r$, any CAS can get the probabilities within a second.
Also, this may be of interest: Find the ordinary generating function $h(z)$ for a Gambler's Ruin variation.
