Question

I am new to Mathematica and am trying to figure out how to dynamically generate a system of ODEs. For example I have a system of 100 equations where every 10 are essentially the same but with slightly different parameters that can be read from a vector (of length 10). I would like to write the 10 equations out, then loop over some iterator to generate all 100 equations. Is there a standard way to do this?

For example, here is a system of 30 equations (for i in 1:10):

 dX_i/dt = -\beta*X_i*Y_i + \delta_{i-1}*X_{i-1} - \delta_i*X_{i}
 dY_i/dt = \beta*X_i*Y_i - \gamma_i*Y_i + \delta_{i-1}*Y_{i-1} - \delta_i*Y_{i} 
 dZ_i/dt = \gamma_i*Y_i + \delta_{i-1}*Z_{i-1} - \delta_i*Z_{i} 

It seems redundant to copy paste new equations if I increase the i to say, 100 (i.e. giving us three hundred ODEs).

Was it helpful?

Solution

Here it goes, but probably Mathematica is not going to be able to solve it (depending on your coefficients)

Table[(delta[i] = i; gamma[i] = -i), {i, 0, 10}];
b = 1;
DSolve[Flatten@Table[{
    x[i]'[t] == -b x[i][t] y[i][t] + delta[i - 1] x[i - 1][t] - delta[i] x[i][t],
    y[i]'[t] == -b x[i][t] y[i][t] - gamma[i] y[i][t] + delta[i - 1] y[i - 1][t] - delta[i] y[i][t],
    z[i]'[t] ==  gamma[i] y[i][t] + delta[i - 1] z[i - 1][t] - delta[i] z[i][t]}, {i, 1, 10}], 
 Flatten[Table[{x[i][t], y[i][t], z[i][t]}, {i, 1, 10}]], t]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top