Defining a vector differential equation using @ode_def

I am trying to write a differential equation for replicator dynamics, which, in the simplest, case is a vector differential equation with n components where

$$ \dot x_i = x_i ( (Ax)_i - x’ A x ) $$

So, I tried the following code

using DifferentialEquations,  ParameterizedFunctions

replicator! = @ode_def Replicator begin
    dx = x .* ( A*x .- x'*A*x )
end A

x0 = [0.33 ; 0.33 ; 0.33]
tspan = (1., 100.)
A = [0. -1. 1.; 1. 0. -1.; -1. 1. 0.]


prob = ODEProblem(replicator!, x0, tspan, A )
sol = solve(prob)

but I get

retcode: Success
Interpolation: Automatic order switching interpolation
t: 10-element Array{Float64,1}:
   1.0               
   1.000001          
   1.000011          
   1.000111          
   1.0011109999999999
   1.0111109999999999
   1.1111109999999997
   2.1111109999999993
  12.111110999999994 
 100.0               
u: 10-element Array{Array{Float64,1},1}:
 [0.33, 0.33, 0.33]
 [0.33, 0.33, 0.33]
 [0.33, 0.33, 0.33]
 [0.33, 0.33, 0.33]
 [0.33, 0.33, 0.33]
 [0.33, 0.33, 0.33]
 [0.33, 0.33, 0.33]
 [0.33, 0.33, 0.33]
 [0.33, 0.33, 0.33]
 [0.33, 0.33, 0.33]

Why is only one component of the state changing?

@ode_def is for small ODEs with named components all acting in scalar ways. Instead of @ode_def, use a normal Julia function f(du,u,p,t) for this kind of thing.

1 Like

Thanks for the clarification. Indeed, normally defined functions work well.