I would appreciate help in a problem that I cannot figure out where am I doing the mistake. The mistake could be something I am unaware of so please excuse my lack of knowledge.
I am trying to solve the equation of motion, $$M \ddot{x} + K x = F,$$ where $M$, $K$, and $F$ are variables independent of $x$, and $\ddot{x}=\frac{d^2x}{dt^2}$. Using a central difference finite scheme, I rewrote the equation as,
$$M \frac{ x_{i+1} - 2x_i + x_{i-1} }{ {\Delta t} ^2 } + Kx = F.$$
Then, I am solving this equation for $x_{i+1}$ at every time step $i$ as,
$$ x_{i+1} = \frac{{\Delta t}^2}{M} \cdot \left( F - K x + \frac{M}{{\Delta t}^2} \cdot 2 x_i - \frac{M}{{\Delta t}^2} \cdot x_{i-1} \right).$$
Now to solve this problem, one needs two initial conditions, to my knowledge, namely, $x(0)$ and $\dot{x}(0)$. At the first time step, I am setting $x_i$ to the $x(0)$ initial condition. Now I am stuck with two problems:
- What value should I set $x_{i-1}$ at first time step?
- How can I apply the initial condition $\dot{x}(0)$?

One trick is to introduce "ghost cells" like $x_{-1}$ with the definition per boundary condition $$ \frac{x_1-x_{-1}}{2Δt}=\dot x(0)\implies x_{-1}=x_1-2Δt\,\dot x(0) $$ Now you can either add this to the system, or directly eliminate $x_{-1}$ against the differential equation centered at $x_0$.
Another way to use the boundary condition with a sufficiently high order is to use a forward differentiation formula of that order, like in the second order $$ \frac{-3x_0+4x_1-x_2}{2Δt}=\dot x(0). $$