## Multicompartment modelling / Arrays of state variables and parameters

Help
2014-06-05
2014-06-05
• Dear all,
I need to study a system of N coupled oscillators, where each oscillator is itself described by 2 state variables, let's say x,y and a parameter vector p={p1,p2,p3...}. Is there a fast way to specify this system in terms of RHS in PyDSTool?

In XPPAUT for example, this is immediate using the "network" option:

http://www.math.pitt.edu/~bard/xpp/help/xppexample.html#net

which allows some sort of indexing.
In PyDSTool using this array-like notation however does no seem possible, or I could not find any example in the tutorial. Hence, do I need to write a dictionary with single individual entries for each state variable/equation and expand parameter arrays too?

For example, let's say the oscillator is described by:

dx/dt = f(x,y,p1)
dy/dt = g(x,y,p2)

if I have N oscillators coupled by y like:

dx[i]/dt = f(x[i],y[i-1],p1[i])
dy[i]/dt = g(x[i],y[i-1],p2[i])

do I need to explicitly write all equations and specify accordingly equal number of state variables and parameters individually? i.e.

dx_0/dt = ...
dy_0/dt = ...

dx_1/dt = f(x_1,y_0,p1_1)
dy_1/dt = f(x_1,y_0,p2_1)

dx_2/dt = f(x_2,y_1,p1_2)
dy_2/dt = f(x_2,y_1,p2_2)

...
...

and so on...

Cheers,

M

• Rob Clewley
2014-06-05

For one thing, being a python environment, you can always write a python loop over index i that builds the strings for the equations according to the simple coupling and naming rules. However, yes, there is syntax for doing this directly in PyDST, much the same as with XPP. You would macro-define an array of variables with an entry in your RHS def dict such as (for N=10 using cyclic boundary conditions):

```'x[i]': 'for(i, 1, 8, f(x[i],y[i-1],p1_[i]))',
'y[i]': '', # etc.
'x0': 'f(x0, y9, p1_0)',
'x9': '', # etc.
# etc.
```

with special cases to handle the endpoint boundaries and suitably defined parameters p1_0 - p1_9.

Last edit: Rob Clewley 2014-06-05