Hello,
I have a question about how to make an If[condition,then,else] statements for recursive expressions. I want to model a population that can't be negative so that when it hits 0 or a negative value, it assumes the value of zero for all subsequent time points. This is a bit tricky as my variables depend on each other.
Right, so here is more information about the model that I've created (I really don't mean to start a discussion about Polio or Syria, it's just a school project and I'm sorry if its offensive. I know Polio is not the biggest problem, I just thought it would be interesting)
The question: To look at the spread of a disease and see which parameters are the most important to minimize the number of infected people.
Polio (P)== P*S*G +(Mp)+P(1-d-h) Immunized (Imm) == P*h+S*v+Imm+Mimm Susceptable (S) == S*(1-v-P*G)+Ms +b
Where the parameters are: G = rate of infection from a polio infected indiv to a susceptable indiv.d = death from polioh = people with polio who get healthy and turn into immune healthy individuals v = rate of effective vaccination from susceptable people to immune peopleb = births, all babies are born susceptable to polioM = immigration to syria - emmigration from sytria (this can also include death from other causes such as war) -> the M have subscripts as they are different for each variable.
Here is my set of equations where P, Imm, and S are variables to describe the groups in my population. t is time and the rest are parameters that I can set and manipulate.
P[t_, G_, Mp_, d_, h_, v_, Ms_, Mimm_, b_] :=
P[t, G, Mp, d, h, v, Ms, Mimm, b] =
P[t - 1, G, Mp, d, h, v, Ms, Mimm, b]*
S[t - 1, G, Mp, d, G, v, Ms, Mimm, b] *G + Mp +
P[t - 1, G, Mp, d, h, v, Ms, Mimm, b] (1 - d - h)
Imm[t_, G_, Mp_, d_, h_, v_, Ms_, Mimm_, b_] :=
P[t - 1, G, Mp, d, h, v, Ms, Mimm, b]*h +
S[t - 1, G, Mp, d, G, v, Ms, Mimm, b] *v +
Imm[t - 1, G, Mp, d, h, v, Ms, Mimm, b] + Mimm
S[t_, G_, Mp_, d_, h_, v_, Ms_, Mimm_, b_] :=
S[t, G, Mp, d, G, v, Ms, Mimm, b] =
S[t - 1, G, Mp, d, G, v, Ms, Mimm,
b] (1 - v - P[t - 1, G, Mp, d, h, v, Ms, Mimm, b]*G) + Ms + b
I thought it would work if I had written this (with an If statement modifying each definition)
P[t_, G_, Mp_, d_, h_, v_, Ms_, Mimm_, b_] :=
If[P[t-1, G, Mp, d, h, v, Ms, Mimm, b]>0, P[t, G, Mp, d, h, v, Ms, Mimm, b] =
P[t - 1, G, Mp, d, h, v, Ms, Mimm, b]*
S[t - 1, G, Mp, d, G, v, Ms, Mimm, b] *G + Mp +
P[t - 1, G, Mp, d, h, v, Ms, Mimm, b] (1 - d - h), P[t, G, Mp, d, h, v, Ms, Mimm, b]=0]
But I get an error where the "recursion depth was exceeded".
I think there is an easy way of doing this, but I can't seem to find it. Any help would be appreciated, thank you!
-M