# Why does finite difference approximation method and RK4 method produce different result for an initial value problem?

I'm trying to develop my knowledge about numerical methods. When studying finite difference methods in the boundary value problem I try to realize my code solving problem I came up with.

I start thinking about easy problem $u''=1, u(0)=0, u'(0)=0, x\in [0,1]$. I took $h=0.1$, and used the second finite difference $$\frac{u_{i-1} -2u_i+u_{i+1}}{h^2}=1, u_0 = 0, \frac{u_1-u_0}{h}=0$$

Having solved the finite difference system on the grid with 10 nodes I noticed that my solution differs with analytical one sharply. I realized then that I actually should have solved initial value problem instead of boundary value problem. Then I used RK4 for solving this problem and it gave good results.

I wonder why finite difference method produce this result with my first formulation of the problem? What is the problem I solved at the first time?

• $\dfrac{u_{i-1} -2u_i+u_{i+1}}{h^2}=1$ is going to lead to a quadratic solution and your blue line seems to meet this, looking like a parabola with roughly the correct curvature. But it is in the wrong position, and in particular I cannot see what made you think it would go negative – Henry Jan 20 '17 at 9:52
• My questions were why finite different method cannot solve initial value formulation of the problem I came up with and what have been solved by me actually when using finite difference method? As you can see the blue line is more like a solution of the boundary problem $u_0 = 0, u_n = 1$. – lR55 Jan 20 '17 at 16:31
• The problem is in the implementation. Check your code. – Eliad Jan 23 '17 at 16:14
• Here the LINK. You can execute my script and see my results for $u$. Choose Octave as programming language – lR55 Jan 23 '17 at 17:59
• You are mixing up concepts here: RK4 is also a finite difference method. – Winther Jan 25 '17 at 23:05