Density of hitting time for a two-sided barrior for Brownian motion with drift For the following Brownian motion with drift $X_t = X_0 + \mu t + \sigma B_t$ where $\mu \in \mathbb{R}$, $ \sigma > 0$ and $X_0 \in \mathbb{R}$ which is a solution to the stochastic differential equation:
\begin{align*}
dX_t = \mu dt + \sigma dB_t \ .
\end{align*}
I am interested in finding the probability density funtion of the following stopping time:
\begin{align*}
\tau = \inf[t: X_t \notin (a,b) ] \ .
\end{align*}
Where we for the initial position have $X_0 \in (a,b)$. The corresponding forward Kolmologov equation to the above SDE is:
\begin{align*}
\frac{\partial u}{\partial t} = \frac{\sigma^2}{2} \frac{\partial^2u}{\partial x^2} - \mu  \frac{\partial u}{\partial x} \ .
\end{align*}
From the answers in the link Density of first hitting time of Brownian motion with drift it should be possible to find the density of $\tau$ as a function of $t$ by solving the forward Kolmologov equation with the initial condition $u(x,t=0) = \delta(x-x_0)$ and with boundary condition $u(a,t)=u(b,t) = 0$ for all $t>0$. I have already tried the same strategy as mentioned in the link, but it doesn't seem to work. Do anyone have a suggesten to another strategy to solve this problem?
 A: I have now found all mistakes, so here is the final answer.
We use separation of variables to find a solution we define $u(x,t) = f(x)g(t)$ then we get the two equations:
\begin{align*}
\begin{cases}
    D\partial_x^2 f - \mu \partial_x f + \lambda f = 0 \\
    \partial_t g = - \lambda g
\end{cases}
\end{align*}
where we have introduced the constant $-\lambda$ and where $D=σ^2/2$. We start by solving the time dependent equation, this equation has the general solution:
\begin{align*}
    g(t) = g(t_0) \exp\big(-\lambda(t-t_0) \big) \ .
\end{align*}
For the spatial dependent solution $f$, we put $f(x) = \exp(rx)$ then we get:
\begin{align*}
    D r^2 \exp(rx) - \mu r \exp(rx) + \lambda \exp(rx) = 0 \ .
\end{align*}
We divide by $\exp(rx)$ and solve the corresponding second order polynomial:
\begin{align*}
    r_1 &= \frac{\mu + \sqrt{\mu^2 - 4 D \lambda}}{2 D} \ , \\
    r_2 &= \frac{\mu - \sqrt{\mu^2 - 4 D \lambda}}{2 D} \ .
\end{align*}
Now if $\mu^2 - 4 D \lambda>0$ and $r_1 \neq r_2$ is not equal then we have the solution:
\begin{align*}
    f(x) = A \exp(r_1 x) + B \exp(r_2 x) \ .
\end{align*}
If $\mu^2 - 4 D \lambda=0$ then $r_1 = r_2$ and we then have the solution:
\begin{align*}
    f(x) = A \exp(r x) + B x\exp(r x) \ .
\end{align*}
If $\mu^2 - 4 D \lambda<0$ then the roots are complex, thus we have $r_1 = \frac{\mu + i \sqrt{4 D \lambda - \mu^2}}{2D}$, $r_2 = \frac{\mu - i \sqrt{4 D \lambda - \mu^2}}{2D}$ and $\beta = \frac{\sqrt{4 D \lambda - \mu^2}}{2D}$. The solution is:
\begin{align*}
    f(x) = \exp\left(\frac{\mu x}{2D}\right) \left(A \sin(\beta x) + B \cos(\beta x) \right)  \ .
\end{align*}
Using the boundary condition only the last expression for $f$ will give us a non-trivial solution. Thus we have:
\begin{align*}
    f(a) &= \exp\left(\frac{\mu a}{2D}\right) \left(A \sin(\beta a) + B \cos(\beta a) \right)  = 0 \ \Rightarrow \ A = - B \frac{\cos(\beta a)}{ \sin(\beta a)} \ .
\end{align*}
Using the other boundary point we get:
\begin{align*}
    f(b) &= \exp\left(\frac{\mu b}{2D}\right) \left( - B \frac{\cos(\beta a)}{ \sin(\beta a)} \sin(\beta b) + B \cos(\beta b) \right)  \ .
\end{align*}
Form this we conclude that:
\begin{align*}
    B \left ( \cos(\beta b) - \frac{\cos(\beta a)}{ \sin(\beta a)} \sin(\beta b) \right) = 0 \ .
\end{align*}
If $B$ is zero we get a trivial solution, thus $B$ is not zero and then we conclude that $\cos(\beta b) - \frac{\cos(\beta a)}{ \sin(\beta a)} \sin(\beta b) = 0$. By multiplication with $-\sin(\beta a)$ and using the following formula:
\begin{align*}
    \sin(\beta b)\cos(\beta a) - \cos(\beta b) \sin(\beta a) = \sin(\beta ( b - a) ) \ ,
\end{align*}
we see that:
\begin{align*}
    \sin(\beta ( b - a) ) = 0 \ .
\end{align*}
This is true for $\beta ( b - a) = n \pi$ where $n \in \mathbb{Z}$. By the formula $\beta = \frac{\sqrt{4 D \lambda - \mu^2}}{2D}$ we see that there is not just one possible constant $\lambda$, but one for every $n \in \mathbb{Z}$:
\begin{align*}
    \lambda_n = D \left( \left( \frac{n \pi}{b-a} \right)^2 + \left( \frac{\mu}{2D} \right)^2 \right) \ , \ \ n \in \mathbb{Z} \ . 
\end{align*}
Where we have introduced a subscript $n$ to the possible $\lambda$ constants to separate them. Now by the linearity of the equation we get a Fourier series as a solution:
\begin{align*}
    u(x,t) = \exp\left(\frac{\mu x}{2D}\right) \sum_{n \in \mathbb{Z}}  \left(A_n \sin\left(\frac{n \pi x}{b-a} \right) + B_n \cos\left(\frac{n \pi x}{b-a} \right) \right) \exp\big(-\lambda_n(t-t_0) \big) \ .
\end{align*}
Where $g(t_0)$ has been left out since it can be absorbed into the constants $A_n$ and $B_n$. Now because of the odd and even properties of sine and cosine we see that:
\begin{align*}
    A_n \sin\left(\frac{n \pi x}{b-a} \right) + A_{-n} \sin\left(\frac{-n \pi x}{b-a} \right) &= (A_n - A_{-n}) \sin\left(\frac{n \pi x}{b-a} \right) \ , \ n \in \mathbb{N} \ , \\
     B_n \cos\left(\frac{n \pi x}{b-a} \right) + B_{-n} \cos\left(\frac{-n \pi x}{b-a} \right) &= (B_n + B_{-n}) \cos\left(\frac{n \pi x}{b-a} \right)  \ , \ n \in \mathbb{N}  \ .
\end{align*}
Because of these formulas and the squared $n^2$ in the expression of $\lambda_n$ we can limit our sum to $n \in \mathbb{N}_0$ thus:
\begin{align*}
    u(x,t) = \exp\left(\frac{\mu x}{2D}\right) \sum_{n \in \mathbb{N}_0} \left(A_n \sin\left(\frac{n \pi x}{b-a} \right) + B_n \cos\left(\frac{n \pi x}{b-a} \right) \right) \exp\big(-\lambda_n(t-t_0) \big) \ .
\end{align*}
One can show the following for sine and cosine:
\begin{align*}
    \int_{a}^b \cos\left(\frac{n \pi x}{b-a} \right) \sin\left(\frac{m \pi x}{b-a} \right) dx &= 0 \ , \ \forall n,m \ . \\
    \int_a^b \cos\left(\frac{n \pi x}{b-a} \right) \cos\left(\frac{n \pi x}{b-a} \right) dx &= 0 \ , \ n \neq m \ . \\
    \int_a^b \sin\left(\frac{n \pi x}{b-a} \right)  \sin\left(\frac{n \pi x}{b-a} \right) dx &= 0 \ , \ n \neq m \ . \\
\end{align*}
For the two last expressions, in the case $m=n$, we have:
\begin{align*}
     \int_a^b \cos^2\left(\frac{n \pi x}{b-a} \right) dx &= \frac{b-a}{2} \ ,
     \\
     \int_a^b \sin^2\left(\frac{n \pi x}{b-a} \right) dx &= \frac{b-a}{2} \ .
\end{align*}
From these formulas one can deduce that:
\begin{align*}
    B_n = \frac{2}{b-a}  \exp\big(\lambda_n(t-t_0) \big) \int_a^b u(x,t) \cos\left(\frac{n \pi x}{b-a} \right) \exp\left(\frac{-\mu x}{2D}\right) dx \ , \\
    A_n = \frac{2}{b-a} \exp\big(\lambda_n(t-t_0) \big) \int_a^b u(x,t)  \sin\left(\frac{n \pi x}{b-a} \right) \exp\left(\frac{-\mu x}{2D}\right) dx \ .
\end{align*}
Since this has to be true for all $t \geq t_0$ we can put $t=t_0$ then we get:
\begin{align*}
    B_n = \frac{2}{b-a} \int_a^b \delta(x-x_0) \cos\left(\frac{n \pi x}{b-a} \right) \exp\left(\frac{-\mu x}{2D}\right) dx = \frac{2}{b-a} \cos\left(\frac{n \pi x_0}{b-a} \right) \exp\left(\frac{-\mu x_0}{2D}\right) \ , \\
    A_n = \frac{2}{b-a}  \int_a^b \delta(x-x_0)  \sin\left(\frac{n \pi x}{b-a} \right) \exp\left(\frac{-\mu x}{2D}\right) dx = \frac{2}{b-a} \sin\left(\frac{n \pi x_0}{b-a} \right) \exp\left(\frac{-\mu x_0}{2D}\right) \ .
\end{align*}
Inserting this back into our solution we get:
\begin{align*}
    u(x,t) = \frac{2}{b-a} \exp\left(\frac{\mu(x-x_0)}{2D}\right) \sum_{n \in \mathbb{N}_0} \cos\left(\frac{n \pi (x-x_0)}{b-a} \right) \exp\big(-\lambda_n(t-t_0) \big)
\end{align*}
We now define the survival probability as:
\begin{align*}
    S(t) = \int_a^b u(x,t) dx \ .
\end{align*}
We see that:
\begin{align*}
    S(t) &= \frac{2}{b-a} \sum_{n \in \mathbb{N}_0} \exp\big(-\lambda_n(t-t_0) \big) \int_a^b \exp\left( \frac{\mu (x-x_0)}{2D} \right) \cos\left( \frac{n \pi (x-x_0)}{b-a} \right) dx \ .
\end{align*}
Calculating the integral we have:
\begin{align*}
    \int_a^b \exp\left( \frac{\mu (x-x_0)}{2D} \right) &\cos\left( \frac{n \pi (x-x_0)}{b-a} \right) dx = \\
    \frac{D}{\lambda_n} \Bigg( \frac{\mu}{2D} & \left( \exp\left(\frac{\mu(b-x_0)}{2D} \right) \cos\left( \frac{n \pi (b-x_0)}{b-a} \right) - \exp\left(\frac{\mu(a-x_0)}{2D} \right) \cos\left( \frac{n \pi (a-x_0)}{b-a} \right) \right) \\
    + \frac{n \pi}{b-a} & \left(  \exp\left(\frac{\mu(b-x_0)}{2D} \right) \sin\left( \frac{n \pi (b-x_0)}{b-a} \right) -  \exp\left(\frac{\mu(a-x_0)}{2D} \right) \sin\left( \frac{n \pi (a-x_0)}{b-a} \right) \right) \Bigg)\ .
\end{align*}
By inserting this in the expression for $S(t)$ we get:
\begin{align*}
    S(t) &=  \frac{2}{b-a} \exp\left(\frac{\mu(b-x_0)}{2D} \right)  \sum_{n \in \mathbb{N}_0} \frac{D}{\lambda_n} \frac{\mu}{2D} \cos\left( \frac{n \pi (b-x_0)}{b-a} \right) \exp\big(-\lambda_n(t-t_0) \big) \\
    &- \frac{2}{b-a} \exp\left(\frac{\mu(a-x_0)}{2D} \right)  \sum_{n \in \mathbb{N}_0} \frac{D}{\lambda_n} \frac{\mu}{2D} \cos\left( \frac{n \pi (a-x_0)}{b-a} \right) \exp\big(-\lambda_n(t-t_0) \big) \\
    &+ \frac{2}{b-a} \exp\left(\frac{\mu(b-x_0)}{2D} \right)  \sum_{n \in \mathbb{N}_0} \frac{D}{\lambda_n} \frac{n \pi}{b-a} \sin\left( \frac{n \pi (b-x_0)}{b-a} \right) \exp\big(-\lambda_n(t-t_0) \big) \\
    &- \frac{2}{b-a} \exp\left(\frac{\mu(a-x_0)}{2D} \right)  \sum_{n \in \mathbb{N}_0} \frac{D}{\lambda_n} \frac{n \pi}{b-a} \sin\left( \frac{n \pi (a-x_0)}{b-a} \right) \exp\big(-\lambda_n(t-t_0) \big) \ .
\end{align*}
Now the first hitting time density $f_{\tau}(t)$ can be found by the expression:
\begin{align*}
    f_{\tau}(t) = - \frac{dS}{dt} \ .
\end{align*}
$f_\tau$ is also known as the first passage time density. we see that:
\begin{align*}
    f_{\tau}(t) &= \frac{2}{b-a} \exp\left(\frac{\mu(b-x_0)}{2D} \right)  \sum_{n \in \mathbb{N}_0} \frac{\mu}{2} \cos\left( \frac{n \pi (b-x_0)}{b-a} \right) \exp\big(-\lambda_n(t-t_0) \big) \\
    &- \frac{2}{b-a} \exp\left(\frac{\mu(a-x_0)}{2D} \right)  \sum_{n \in \mathbb{N}_0}  \frac{\mu}{2} \cos\left( \frac{n \pi (a-x_0)}{b-a} \right) \exp\big(-\lambda_n(t-t_0) \big) \\
    &+ \frac{2}{b-a} \exp\left(\frac{\mu(b-x_0)}{2D} \right)  \sum_{n \in \mathbb{N}_0} D \frac{n \pi}{b-a} \sin\left( \frac{n \pi (b-x_0)}{b-a} \right) \exp\big(-\lambda_n(t-t_0) \big) \\
    &- \frac{2}{b-a} \exp\left(\frac{\mu(a-x_0)}{2D} \right)  \sum_{n \in \mathbb{N}_0} D \frac{n \pi}{b-a} \sin\left( \frac{n \pi (a-x_0)}{b-a} \right) \exp\big(-\lambda_n(t-t_0) \big) \ .
\end{align*}
For convenience we define:
\begin{align*}
    v(x,t) = \frac{2}{b-a} \exp\left(\frac{\mu(x-x_0)}{2D} \right)  \sum_{n \in \mathbb{N}_0} \frac{n \pi}{b-a} \sin\left( \frac{n \pi (x-x_0)}{b-a} \right) \exp\big(-\lambda_n(t-t_0) \big) \ .
\end{align*}
Then we have:
\begin{align*}
    f_{\tau}(t) &= \frac{\mu}{2} \Big( u(b,t) - u(a,t) \Big) + D \Big( v(b,t) - v(a,t) \Big) \ .
\end{align*}
By our boundary condition $u(b,t) = u(a,t) = 0$ thus:
\begin{align*}
    f_{\tau}(t) &= D \Big( v(b,t) - v(a,t) \Big) \ .
\end{align*}
The following plots are for $a=-1$, $b=1$, $x_0=0$ and $t_0 = 0$. In the plots we have $u:=\mu$.


