One can try to deal with this using a special reflection from half-line to the entire line, but I prefer a direct approach. The characteristics are lines $t=t_0+s$, $x=x_0+3s$, with parameter $s$. Along any such line we have $du/ds = -2u$, and solving this ODE yields $$u(t_0+s,x_0+3s)=e^{-2s}u(t_0,x_0)$$
It remains to figure out what $(t_0,x_0)$ should be here. Think of going backward along a characteristic line: you hit either $t=0$ or $x=0$
Accordingly, there are two cases:
- If $x>3t$, then the initial point is $(0,x-3t)$, at which the initial value is $\sin(x-3t)$. Also, $s=t$ here, leading to $u(x,t)=e^{-2t}\sin(x-3t)$.
- If $x<3t$, then the initial point is $(t-x/3,0)$, at which the initial value is $t-x/3$. Also, $s=x/3$ here, leading to $u(x,t)=e^{-2x/3}(t-x/3)$.
These give the same result on the boundary $3x=t$, which is nice, and is a reflection of the fact that $(\sin 3x)_{x=0} = (t)_{t=0}$. The solution is not differentiable on $x=3t$, which is not unusual for the transport equation: it carries forward whatever singularities and corners were present in the initial data. Here the data had a "corner" due to the combination of initial and boundary conditions.
Update: Let $u(x,t)$ be the solution of
\begin{align} u_t-u_{xx}&=0, \quad 0<x<4, \quad
t>0\\u(x,0)&=v(x)-f(x),\\u(0,t)&=0,\\u(4,t)&=0. \end{align}
First note that $f''(x)=-\cosh(x)$. Let $w(x,t)=u(x,t)+f(x)$. Then
$$ w_t-w_{xx}=u_t-u_xx-f''(x)=\cosh(x), \quad 0<x<4, t>0 $$
and
$$ w(x,0)=u(x,0)+f(x)=v(x), w(0,t)=u(0,t)+f(0)=0, w(4,t)=u(4,t)+f(4)=0. $$
Namely, $w(x,t)$ is the full solution of the original equation.
Note that $\{\sin(\frac{n\pi x}{4})\}$ is dense in $L=\{u\in L^2([0,4]): u(0)=u(4)=0\}$. Let the solution have the form
$$ u(x,t)=\sum_{n=1}^\infty a_n(t)\sin(\frac{n\pi x}{4}). $$
Then setting $u_t-u_{xx}=0$ gives
$$ \sum_{n=1}^\infty \bigg[a_n'(t)+\frac{n^2\pi^2}{16}a_n(t)\bigg]\sin(\frac{n\pi x}{4}) =0 $$
and hence
$$ a_n'(t)+\frac{n^2\pi^2}{16}a_n(t)=0, n=1,2,\cdots. \tag{1}$$
(1) has the general solution
$$ a_n(t)=C_ne^{-\frac{n^2\pi^2}{16}t}.$$
So
$$ u(x,t)=\sum_{n=1}^\infty C_ne^{-\frac{n^2\pi^2}{16}t}\sin(\frac{n\pi x}{4}). $$
But $u(x,0)=v(x)-f(x)$ gives
$$ \sum_{n=1}^\infty C_n\sin(\frac{n\pi x}{4})=v(x)-f(x). $$
Using
$$ \frac1{\sqrt{2}}\int_0^4\sin(\frac{m\pi x}{4})\sin(\frac{n\pi x}{4})dx=\delta_{mn} $$
one has
$$ C_n=\sqrt2\int_0^4(v(x)-f(x))\sin(\frac{n\pi x}{4})dx. $$
Best Answer
Not true as stated. There are lots of numerical boundary value problem solvers out there, one of better known is in Matlab PDE toolbox. The whole industry of Finite Element Method begs to disagree with your "needs to solved analytically" statement.
But you are right to say that
Initial value problems (for ODE and PDE) can be solved by marching forward in time. For example, a simple solver for the diffusion equation would take three consecutive values of $u$ at time step $k$, say $u^{k}_{i-1}$, $u^k_i$, $u^k_{i+1}$, and calculate $$u^{k+1}_i = bu^k_{i-1}+(1-2b)u^k_i+bu^k_{i+1}$$ where $0<b<1/2$ comes from the diffusion coefficient and the sizes of time step and space step.
Not so for boundary value problems. As you remarked, for ODE there is the shooting method, which attempts to solve a BVP by means of several IVPs. But the more systematic way, which works for both ODE and PDE, is to express the discrete form of PDE as a large (but sparse) linear system, and hit it with a specialized linear solver. For example, if I'm solving a boundary value problem for the Laplace equation, my linear system might consist of equations $$u_{i\ j}=\frac14(u_{i-1\ j}+u_{i+1\ j} + u_{i\ j-1}+u_{i\ j+1})$$ which together with boundary conditions form a linear system with unique solution.
One practical consequence of this difference is that solution of initial value problems for PDE can be adapted to parallel computing easier than solution of boundary value problems.