You have to convert the 2nd order equation to a system of order 1 at first. Accumulating dx2/dt2 is not meaingful.
The 2nd derivative at the point [t, x, dxdt] is:
dx2dt2 = -(dxdt^2 + cos(t)) / x
You use this acceleration to calculate the velocity, and the velocity to get the position in each time step.
