MATLAB: solving 1st order hyperbolic equation in 2 spacial dimensions

985 Views Asked by At

According to wikipedia, the equation

$$\psi_t + \mathbf{u} \cdot \nabla \psi =0$$

is hyperbolic. However, when I want to solve it in MATLAB using the pde toolbox (link), the general formula for a hyperbolic equation appears to be:

$$\psi_{tt} - \nabla \cdot (C\nabla\psi)+a\psi=f$$

Which is hyperbolic yes, but second order. I can't seem to find a way how to solve a simpler, 1st order problem. Maybe there is some way to transform it? I can't find anything in the toolbox documentation.

1

There are 1 best solutions below

4
On BEST ANSWER

I don't think there is a way to use the toolbox (see here), but it should be simple to implement a finite difference method by hand:

Write

$$ \psi_t = -u_1 \psi_x - u_2 \psi_y, $$

then discretize (I'll use the first-order forward difference in $t$, and the first-order centered difference in $x,y$)

$$ \frac{\psi(t + h) - \psi(t)}{h}\\ = -u_1(x,y)\frac{\frac12\psi(x+k,y) - \frac12\psi(x-k,y)}{k} -u_2(x,y)\frac{\frac12\psi(x,y+k) - \frac12\psi(x,y-k)}{k} $$ so $$ \psi(t + h) = \\ \psi(t) -\frac{h}{2k}\left(u_1(x,y)(\psi(x+k,y) - \psi(x-k,y)) +u_2(x,y)(\psi(x,y+k) - \psi(x,y-k))\right). $$

Then your method is something like (assuming you are solving on $(t,x,y) \in [0,T] \times [0,L_x] \times [0,L_y]$)

psi(0,x,y) = initial_condition(x,y);
for t = 0 : h : T
    for x = 0 : k : L_x
        for y = 0 : k : L_y
            psi(t + h,x,y) = psi(t,x,y) ...
             - (h/(2*k))*(u_1(x,y)*(psi(t,x+k,y) - psi(t,x-k,y)) ...
             + u_2(x,y)*(psi(t,x,y+k) - psi(t,x,y-k)));
        end
    end
end

In practice, you will want psi to have integer indices, but this illustrates the main idea; you will also need to treat the boundary more carefully, notice phi(t,x,y-k) is going to give you problems for $y = 0$, etc. There is also some need to consider whether this scheme converges, etc. (this can depend on the choice of discretization, as well as the relative size of $h$ and $k$).

For more on all this, I recommend looking at Strikwerda's book. I know this probably seems like a lot to go through and learn just to solve a single PDE, but I can promise you this is a very useful general skillset to have if you think there are more PDEs in your future (in which case, you will quickly outgrow the Matlab toolbox).