# Unstable solution for simple harmonic motion using dormand-prince and RK4 method

I am trying to solve the differential equation for a simple harmonic motion in javascript that is given by

$$mx'' = -kx$$

We know the solution is a sinusoidal. The problem I face is that the amplitude of the sinusoidals in my solution are increasing exponentially.

So the first method I tried was using the numeric.js, It uses the doramnd-prince method to solve the equation. The relevant code the library uses to solve this ODE is https://github.com/sloisel/numeric/blob/master/src/numeric.js#L2885-L2999

Next I tried this GMA1D library, I think it uses RK4 method. There relevant function that the library use to solve the ODE is here https://github.com/llarsen71/GMA1D/blob/gh-pages/javascripts/ODE.js#L89-L123

Here is my implementation

simulate(){
var state = [this.x, this.dx]
var time = this.T;

//var F = 2*Math.sin((-2) - state[0])
var F = -5*state[0];