Finite Difference method for wave equation into matrix form

571 Views Asked by At

I've got a question to help me understanding the implementation of the finite difference method for a real problem better. In my case the equation to be solved is the wave equation (or practically a guitar string that is released from a position $(\hat x, \hat u).$

$\frac{\partial^2 u}{\partial t^2} = c^2 \frac{\partial^2 u}{\partial x^2}$

The initial conditions are:

$u(x,0) = \hat u \frac{x}{\hat x}$, $x \in [0,\hat x] $

$u(x,0) = \hat u \frac{x}{\hat x}$, $x \in [\hat x, L] $

$\frac{\partial u}{\partial t} = \hat u\frac{x-L}{\hat x - L}$

While the boundary conditions are:

$u (0,t) = 0$

$u(L,t) = 0 $

Basically I understand how the finite difference method works (or the idea behind it), but how do I set up a system of equations to be solved in e.g. MATLAB and how to include the time dependency (I guess this is just by a for-loop from t:dt:tN and every step is saved, so I can go back to step n-1)?

My approximation looks like this:

$u_j^{n+1} = \lambda\cdot[u_{j-1}^n-2u_j^n+u_{j+1}^n]+u_j^{n-1}+2u_j^n$

But then there is the term $\frac{\partial u}{\partial t} = 0$ which I approximate by $\frac{u_{j-1}-u_j}{h}=0$ so that $u_{j-1} = u_j$, right? I would make use of that in time step 1?

And how do I pass the information from the initial condition to the nodes (wouldnt it be quite inaccurate with the term $\hat u\frac{x-L}{\hat x - L}$ to pass these to the nodes in the beginning, depending on how fine I discretize?)

My biggest problem is, I don't have any clue how to start with implementation. In class we mostly worked with the theory or ended with the derivation of the approximation without setting it into a real problem. Another thing: I understood the concept correctly as:

(1) time steps are done by a for- or while-loop

(2) in each time step a solution vector is calculated by using the $n^{th}-1$ solution vector, that I basically end up with a counting loop for time and a method to solve a system of equations?

I hope I forgot nothing to mention or did it wrong, thanks for any help!


Additional: The size of the matrix is: N+1, the same length as the solution vector (to include the boundaries) even though we have only N-1 inner nodes?

I thought of how to solve it by hand to get a better feeling what the problem might be, but I am still lost somehow: Picture of calculation