[differentialequations.jl] stuck at initial value when using function

Hi all,
Being new to Julia, I started playing around a bit with differential equations.
I started with a simple system, du = A * u where A is an n*n array, and u a vector of length n.

when I set up the system as

f(u,p,t) = A*u

and provide initial conditions, it works as intended.
However, when I instead set it up as

function fun!(du,u,p,t)
   du = A*u

the solution maintains stuck at the initial value.
It does work when I write out equations explicitly (du[1] = …, du[2] = …, etc.), but this is not very practical. Also, the size & type of du are exactly the same when I do the matrix multiplication as when I write the equations explicitly. So, I’m a bit puzzled why the matrix multiplication doesn’t work.
Would appreciate some insights!

You need du .= A*u so that du is modified instead of replaced.

The difference a dot can make… :slight_smile:

1 Like
1 Like