runge_kutta_fehlberg45_adaptive_step | R Documentation |
This function returns integrated next step value by Fehlberg4(5) method with controling adaptive step with keeping errors smaller than given parameters
runge_kutta_fehlberg45_adaptive_step(dxdt, x, t, dt, abserr, relerr)
dxdt |
the function for derivative by dxdt(x,t) |
x |
a number, vector or matrix |
t |
time |
dt |
step size |
abserr |
permissible absolute error of calculation |
relerr |
permissible relative error of calculation |
list; x:a number, vector or matrix, t:time, dt:step size
x = c(0.5,0.3)
t = 0
dt = 0.01
dxdt = function(x,t){c(x[1]*(2-3*x[2]),-x[2]*(4-5*x[1]))}
lx1 = numeric(0)
lx2 = numeric(0)
lt = numeric(0)
while(t<10){
n = runge_kutta_fehlberg45_adaptive_step(dxdt,x,t,dt,1e-6,1e-6)
x = n$x
t = n$t
dt = n$dt
lx1 = c(lx1,x[1])
lx2 = c(lx2,x[2])
lt = c(lt,t)
}
plot(lt,lx1,ylim=c(0,1.5))
points(lt,lx2,col="red")
#dt plot
plot(lt[-1]-lt[-length(lt)])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.