I know this code is wrong, but I am not sure why. I have a system of coupled differential equations. The model is given by the following equations:
$\frac{dS_0} {dt} = (1 - \mu_0) \rho_0 S_0 \frac{S_\gamma}{S_\rho} - \gamma_0 S_0$
$\frac{dS_1} {dt} = \mu_0 \rho_0 S_0 \frac{S_\gamma}{S_\rho} - \gamma_1 S_1 + (1 - \mu_1) \rho_1 S_1 \frac{S_\gamma}{S_\rho}$
$\vdots$
$\frac{dS_n}{dt} = \mu_{n-1} \rho_{n-1} S_{n-1} \frac{S_\gamma}{S_\rho} + (1-\mu_n) \rho_n S_n \frac{S_\gamma}{S_\rho} - \gamma_n S_n$.
Caveat: $\frac{S_\gamma}{S_\rho}$ is a constant term that scales cell birth and cell death rates over all life-stages so the population size remains constant over time. I thought it should be simple to solve the system with Mathematica because I have solved the simplest cases of the ODE system by hand (the 2-stage and 3-stage models) and have an idea that if I put it into matrix form correctly, it will have a triangular structure. Here's my code:
(*Change the recursion limit on Wolfram Mathematica on the Cloud*)
(* Define the number of stages *)
n = 2;
(* Define the state vector *)
S = Array[s, n];
(* Define the coefficient vectors *)
\[Mu] = Array[\[Mu], n];
\[Rho] = Array[\[Rho], n];
\[Gamma] = Array[\[Gamma], n];
(* Define the coefficient matrices *)
A = DiagonalMatrix[-\[Gamma]];
B = DiagonalMatrix[(1 - \[Mu]) \[Rho]];
(* Define the derivative of the state vector *)
dSdt = D[S[t], t];
(* Construct the derivative in terms of matrices A and B *)
ode = dSdt == A.S + B.S \[Gamma]/S \[Rho];
(* Define the initial condition vector *)
S0 = {1, 0}; (* First stage = 1, others = 0 *)
(* Solve the ODE system with the initial condition *)
solution = DSolve[{ode, S[0] == S0}, S[t], t]
If there are n=2 stages, there should be two coupled ODEs; if there are three stages, there should be three coupled ODEs. Is this an inefficient way to input everything to make a matrix ODE system? It seems the way I have formed the matrix ODE system here is either incorrect or missing something because when I run DSolve
, it returns it unevaluated. The error message output is: "Function S appears with no arguments." I have searched here a few times to find the best way to formulate similar problems but haven't found anything that jumped out at me as a good way to correct my code.
\[Mu] = Array[\[Mu], n]
because you will get infinite recursion !Mathematica graphics $\endgroup$