Second order 1-D wave equation, Implicit scheme I am trying to solve the second order wave equation in 1 dimension from the implicit method by finite difference.
$$
 \frac{\partial^2U}{\partial t^2} = c^2\frac{\partial^2U}{\partial x^2}  , \quad  t>0
$$
where initially 
$$
U(x,0)=f(x), \quad  \frac{\partial U(x,0)}{\partial t} = g(x)
$$
The discretized form of the above equation can be written as:
$$
\frac{1}{k^2}\delta_t^2 u_i^{n} = \frac{c^2}{h^2} \left(\frac{1}{4} \delta_x^2 u_i^{n+1}+\frac{1}{2} \delta_x^2 u_i^{n}+\frac{1}{4} \delta_x^2 u_i^{n-1}\right)
$$
where 
$$
\delta_t^2 u_i^{n} = u_i^{n+1}-2u_i^{n}+u_i^{n-1}
$$
and
$$
\delta_x^2 u_i^{n} = u_{i+1}^{n}-2u_{i}^{n}+u_{i-1}^{n}
$$
This gives a tridiagonal system of equations. and the stability condition is 
$$r=ck/h >0$$
I don't know how to make the matrix of coefficients. Then I can solve it by any iterative or direct methods. Thanks for any guide.
 A: In particular, this implicit finite-difference method for the wave equation is described in [1]. Let $r=ck/h$, where $k$ is the time step and $h$ is the mesh size. Separating the different time steps from each other, the scheme rewrites as
$$
-u_{i+1}^{n+1} + 2 ( 1+2/r^2 ) u_i^{n+1} - u_{i-1}^{n+1} = 2\left(u_{i+1}^{n} - 2 ( 1-2/r^2 ) u_i^{n} + u_{i-1}^{n}\right) + \left(u_{i+1}^{n-1} - 2 ( 1+2/r^2 ) u_i^{n-1} + u_{i-1}^{n-1}\right) .
$$
Now, let
$$
{\bf K} = \left(\begin{array}{cccc}
2 & -1 & & \\
-1 & \ddots & \ddots & \\
 & \ddots & \ddots & -1 \\
 & & -1 & 2
\end{array}\right) ,\quad
{\bf b} = \left(\begin{array}{c}
-1 \\
0 \\
\vdots \\
0 \\
-1
\end{array}\right) .
$$
The finite-difference scheme can be written in matrix form as
$$
(4/r^2 {\bf I} + {\bf K}){\bf u}^{n+1} + {\bf b} =  2(4/r^2 {\bf I} - {\bf K}) {\bf u}^{n} - 2{\bf b} - (4/r^2 {\bf I} + {\bf K}){\bf u}^{n-1} - {\bf b}
$$
or
$$
{\bf u}^{n+1} = (4/r^2 {\bf I} + {\bf K})^{-1} \left( 2(4/r^2 {\bf I} - {\bf K}) {\bf u}^{n} - 4{\bf b} \right) - {\bf u}^{n-1} ,
$$
where ${\bf I} = {\bf K}^0$ is the identity matrix.

[1] A.R. Mitchell, D.F. Griffiths: The Finite Difference Method in Partial Differential Equations, John Wiley & Sons, 1980.
