○ 4th-order Runge-Kutta(runge-kutta-4.rb)
# ルンゲクッタで積分
require "derivative"
def integral(time, dt, pv, pv0)
if @rfirst == nil
@rfirst = false
@w = pv.dup
end
d1 = derivative(pv, pv0)
@w.spect = pv.spect + d1 * dt / 2.0
d2 = derivative(@w, pv0)
@w.spect = pv.spect + d2 * dt / 2.0
d3 = derivative(@w, pv0)
@w.spect = pv.spect + d3 * dt
d4 = derivative(@w, pv0)
pv.spect = pv.spect + (d1 + d2 * 2.0 + d3 * 2.0 + d4) / 6.0 * dt
time = time + dt
return time, pv
end