How does one implement ODE in netlogo? Right now , I use the Euler method which is solves the the given equations:
R[t+1] = r[t] + v[t] * step-size
V[t+1] = v[t] + f * step-size
Found this similar question, but it suggest uni-directional link from mathematica to netlogo which is makes it not possible to implement.
I looking for something similar to ode solver in matlab?
Best How To :
Partial answer, compare accuracy-runtime estimates for Euler, improved Euler and RK4
Assume that the most time-consuming part is the evaluation of the system function, i.e., the vector arithmetic of the Runge-Kutta methods are a small overhead.
Given a time interval of
T=1, restrict the methods to 100 function evaluations. Then
- Euler performs 100 steps with step size
h=0.01 and global error of the magnitude
- improved Euler has global error order 2 and 2 function evaluations. Thus performs 50 steps with step size
h=0.02 and global error of magnitude
- classical RK4 of order 4 and 4 function evaluations per step performs 25 steps of step size
h=0.04 with global error magnitude
Fixing the global error at about
1e-4 one obtains inversely for number of function evaluations
- 10000 for Euler, with
- 200 for improved Euler, with
- 40 for classical RK4, with
which explains speed differences if the methods are tuned for the same level of the global error.
The strategy for the implementation of RK4 in the ball example is for an ODE system
x is the, possibly very large, state vector
save t0=t, x0=x
evaluate k1 = f(t,x)
set t=t0+h/2, x=x0+h/2*k1
set t=t+h, x=x0+h*k3
In an agent based system it is reasonable to store the components of the state vector belonging to the agent as internal variables of the agent. Then the vector operations are performed by iterating over the agent collection and computing the operation tailored to the internal variables.
A second order ODE is transformed to a first order system as indicated in the question,
x''=a(x,x') gets transformed to
[x',v']=[v, a(x,v)]. The big vector of the agent system is the composed of the collection of the pairs
[x,v] or, if desired, as the concatenation of the collection of all
x components and the collection of all