I've been given the formula for RK2 and shown how to use it on an ODE to solve $y'(t) = f(y, t)$, where $f(y,t)$ is explicitly known.
Equipped only with this knowledge I have been asked to use RK2 on a PDE, where neither side of the equation is known, except that I see that I must substitute the spacial derivative with a finite difference operator. I am required, for the purpose of this assignment to use a center space finite difference, as shown below.
My work so far:
Given $\partial_tu(x,t) = -c\partial_xu(x,t)$ is analogous to $y'(t) = f(y,t)$ when we consider all variables besides t as constants:
$$ k_1 = \Delta t f(y_n, t_n) \\k_2 = \Delta t f(y_n + k_1, t_n + \Delta t)\\ y_{n+1} = y_n + \frac{1}{2}(k_1 +k_2) + \mathcal{O}(\Delta t^3) $$
Becomes:
$$ k_1 = \Delta t f(u_{j+1}, u_{j-1}) = -c\Delta t \frac{u^n_{j+1} - u^n_{j-1}}{2\Delta x} \\k_2 = \Delta t f(u_n +k_1, t_n + \Delta t) = ????? \\ u^{n+1}_j = u^n_j + \frac{1}{2}(k_1 +k_2) + \mathcal{O}(\Delta t^3) $$ $$ \text{where }u^n_j \text{ means } u(x_0 + j\Delta x, n\Delta t) $$
I have no idea how to add $k_1$ to my new "function" of $u_{j+1}$ and $u_{j-1}$ in order to find $k_2$. My textbook (Numerical Recipes [in fortran 77!]) does not review RK2 in combination with PDEs, and neither do my class notes. I have no idea how to functionally put RK2 to work on a PDE without knowing this step. I am not far enough along in the course to make use of linear algebra, though I have seen suggestions to do so.
This question seems quite similar, but I do not understand the accepted answer:
The answer seems to just put finite difference to use. I don't see Runge Kutta used at all. It looks like a finite difference operator is used and that's it.
Also, would the second vector look like $(u_0(t), u_1(t), \dots u_{N-1}(t))^T$? I'm confused by it only having a single entry, as well as why it isn't subtracted instead of added.
It looks like you expand the vector $\frac{d}{dt}u(t)$ using some finite difference method and rearrange the whole thing to get $u^{n+1}_j$ alone on the left hand side, giving us Euler ($\tilde{u}^{n+1}$).
And, I think I see my $k_1$ and $k_2$ buried in the last line of your answer!
– rocksNwaves Mar 02 '18 at 19:05I'm trying to do this derivation that you showed me on paper right now, and I keep getting a $\frac{\Delta x}{c} \frac{d}{dt}\mathbf{u}(t)$ on the right hand side. I expand that using forward time differencing? Is this a mistake on my part? I like to do the derivation myself because I'm bad at math in general. I can't figure out my mistake.
– rocksNwaves Mar 02 '18 at 19:30