# How do I solve this pde (using finite differences)?

How do I solve the pde:

$\ -s_x(x,t) -p(x,t)s_t(x,t)=p(x,t)$

for s(x,t) when p(x,t)=2x, subject to the condition s(0,t)=0?

Generally p(x,t) may not be analytical so I would like to use finite differences to transform this into a linear algebra problem:

$\ (-D_x-pD_t)s=p$ But how do I incorporate my "boundary" condition s(0,t)=0 into this?

To find the solution you will also need an initial condition like $s(x,0)=\phi(x)$, $x\ge0$. Choose $\Delta x>0$ and $\Delta t>0$, and let $s_{j,k}\approx s(j\,\Delta x,k\,\Delta t)$, $p_{j,k}=p(j\,\Delta x,k\,\Delta t)$ for $j,k\ge0$. The initial condition is then $$s_{j,0}=\phi(j\,\Delta x),\quad j\ge0,$$ and the boundary condition $$s_{0,k}=0,\quad k\ge0.$$
The simplest finite difference approximation is $$-\frac{s_{j+1,k}-s_{j,k}}{\Delta x}-p_{j,k}\,\frac{s_{j,k+1}-s_{j,k}}{\Delta t}=p_{j,k},\quad j,k\ge0.$$ If $p_{j,k}\ne0$for all $j,k\ge0$, then $$s_{j,k+1}=\frac{1}{p_{j,k}}\frac{\Delta t}{\Delta x}(s_{j,k}-s_{j+1,k})-\Delta t,\quad j,k\ge0.$$