runge_kutta_fehlberg45_step: Stepper with Runge-Kutta Fehlberg4(5) method

View source: R/odeint.R

runge_kutta_fehlberg45_stepR Documentation

Stepper with Runge-Kutta Fehlberg4(5) method

Description

This function returns integrated next step value by using the Runge-Kutta Fehlberg4(5) method

Usage

runge_kutta_fehlberg45_step(dxdt, x, t, dt)

Arguments

dxdt

the function for derivative by dxdt(x,t)

x

a number, vector or matrix

t

time

dt

step size

Value

list; x: next step x, error: error

Examples

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")

hmito/hmRLib documentation built on March 13, 2024, 9:41 p.m.