In the book, on page $233$, I found that the wave equation:
$$ u_{tt}=u_{xx} \tag 1$$
can be discretized using the following finite difference approximation:
$${ U_{i+1,j}-2U_{i,j}+U_{i-1,j} \over \Delta t^2 } = { U_{i+1,j+1} - 2U_{i+1,j} + U_{i+1,j-1} + U_{i-1,j+1} - 2U_{i-1,j} + U_{i-1,j-1}\over 2\Delta x^2} \tag 2$$
where $i$ represents the time step index and $j$ represents the spatial step index. This is the averaged spatial approximation method and it is unconditionally stable apparently. However, in the book, there is no example that shows how to use this approximation. When I reformulate equation $(2)$ I get the following expression:
$$ -kU_{i+1,j+1} + (1 + 2k)U_{i+1,j} -kU_{i+1,j-1} = 2U_{i,j}+kU_{i-1,j+1}-(1 + 2k)U_{i-1,j} + kU_{i-1,j-1} \tag 3$$
$$k = {\Delta t^2 \over 2 \Delta x^2} \tag 4$$
I know the boundary condition at $x=0$ and $x=x_{max}$. However, it seems to me that I need one more boundary condition in order to use this approximation. To calculate $U_{i+1,2}$, I need to know $U_{i+1,1}$ and $U_{i+1,0}$. The problem is, I only know $U_{i+1,0}$. My question is, do I truly need one more boundary condition to use this approximation? If not, how can I use this approximation correctly?
Wave equation PDE is: $u_{tt}=u_{xx}$
Example problem:
Initial condition: $u(0,x)=\sin(\pi x)$
Boundary conditions: $u(t,0)=0, u(t,1)=0$
Neumann condition: $u_{t}(0,x)=0$
General solution is: $u\! \left(t,x\right)=\sin\! \left(\pi x\right)\cdot \cos\! \left(\pi t\right)$
Solution by finite difference method with Python (using finite difference scheme (2)):
Unfortunately the deviation increases over time with this finite difference scheme.