Finite difference method approximation to an ODE I am trying to solve the ODE $$\frac{d^2 u}{dx^2}+4\frac{du}{dx}+4u=0$$
On the interval [0,1]
with the boundary conditions $u=1$ when $x=0$ and $u=0$ when $x=1$.
If h denotes the step size, the finite difference approximation to the ODE at the $i^{th}$ grid point is 
 $$\left(\frac{1}{h^2}+\frac{2}{h}\right){u_{i+1}}  -\left(\frac{2}{h^2}-4\right){u_i} + \left(\frac{1}{h^2}-\frac{2}{h}\right){u_{i-1}}$$
How is this derived?
 A: A three point finite difference scheme can approximate the first derivative by the following,
$$ f'_j = \frac{ f_{j+1} - f_{j-1} }{2 h },$$
this approximation is second order accurate. 
To get the particular coefficeints being used we write,
$$ f'_j = a f_{j+1} + b f_j + c f_{j-1},$$
we then expand the functions $f_j$'s in a taylor series, for instance,
$$ f_{j+1} = f(x_j+h) = f(x_j) + h f'(x_j) + \frac{h^2}{2} f''(x_j) + O(h^3),$$
which lets us write our approximate derivative as,
$$ f'_j = (a+b+c) f(x_j) + (a-c)h f'(x_j) + (a+c)\frac{h^2}{2} f''(x_j) + O(h^3).$$
This gives us three equations,
$$ a+b+c = 0,$$
$$ a - c = \frac{1}{h},$$ 
$$ a + c = 0,$$
the solution to this system is $a=1/2h, b=0, c=-1/2h$ which is where the approximation comes from.
A: i will use $$u_j = u(jh), h = 1/n.$$
here are finite difference approximations obtained from the taylor series of $u$ centered at $x = jh.$ they are
$$\frac{du}{dx}\Big|_{x = jh} = \frac{u_{j+1}-u_{j-1}}{2h},\frac{d^2u}{dx^2}\Big|_{x = jh} = \frac{u_{j+1}-2u_j + u_{j-1}}{h^2} $$
now you put these in the equation $ \frac{d^2 u}{dx^2}+4\frac{du}{dx}+4u=0.$  you her $$ \frac{u_{j+1}-2u_j + u_{j-1}}{h^2}+ 4 \frac{u_{j+1}-u_{j-1}}{2h}+4u_j = 0$$
you can simplify this and get in a form you have. hope this helps.
