# Defining a vector differential equation using @ode\_def

**URL:** <https://discourse.julialang.org/t/defining-a-vector-differential-equation-using-ode-def/21343>\
**Category:** New to Julia\
**Tags:** diffeq\
**Created:** [March 1, 2019, 1:03pm UTC](https://discourse.julialang.org/t/defining-a-vector-differential-equation-using-ode-def/21343 "2019-03-01T13:03:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adityam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adityam/32/7272_2.png) [@adityam](https://discourse.julialang.org/u/adityam)\
**Post date:** [March 1, 2019, 1:03pm UTC](https://discourse.julialang.org/t/defining-a-vector-differential-equation-using-ode-def/21343/1 "2019-03-01T13:03:46Z")

</div>

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

```julia
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

```julia
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?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 1, 2019, 7:10pm UTC](https://discourse.julialang.org/t/defining-a-vector-differential-equation-using-ode-def/21343/2 "2019-03-01T19:10:12Z")

</div>

`@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.

---

<div class="post-metadata">

**Author:** ![adityam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adityam/32/7272_2.png) [@adityam](https://discourse.julialang.org/u/adityam)\
**Post date:** [March 1, 2019, 10:30pm UTC](https://discourse.julialang.org/t/defining-a-vector-differential-equation-using-ode-def/21343/3 "2019-03-01T22:30:30Z")

</div>

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