runge_kutta_heuneuler_adaptive_step: Controlled stepper with Runge-Kutta Fehlberg4(5) method

View source: R/odeint.R

runge_kutta_heuneuler_adaptive_stepR Documentation

Controlled stepper with Runge-Kutta Fehlberg4(5) method

Description

This function returns integrated next step value by Fehlberg4(5) method with controling adaptive step with keeping errors smaller than given parameters

Usage

runge_kutta_heuneuler_adaptive_step(dxdt, x, t, dt, abserr, relerr)

Arguments

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

Value

list; x:a number, vector or matrix, t:time, dt:step size

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_heuneuler_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)])

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