runge_kutta_fehlberg45_step | R Documentation |
This function returns integrated next step value by using the Runge-Kutta Fehlberg4(5) method
runge_kutta_fehlberg45_step(dxdt, x, t, dt)
dxdt |
the function for derivative by dxdt(x,t) |
x |
a number, vector or matrix |
t |
time |
dt |
step size |
list; x: next step x, error: error
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_step(dxdt,x,t,dt)
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.