0
$\begingroup$

I want to define a variable dependent function which can be used to define another function which depends on the same variable and other variables.

For example, I have a system where I define abundance of c[i, j, t] per unit time using this:

eqs = 
  Table[D[c[i, j, t], t] == k[j - 1] s[i] - (k[j] s[i] + d[j]) c[i, j, t], 
    {i, 1, 5}, {j, 0, 10}];

I can calculate total size of the c[i, j, t] population by this:

NC = Sum[c[i, j, t], {i, 1, 5}, {j, 1, 10}]

Now, what I want to do is write a function such that I can make s[i] in the equation dependent on NC (total population size) at time 't'. Basically, I want a function which can evaluate NC at time t and use that value to calculate s[i]. This s[i] value then will be use to calculate NC at time t + 1.

I was thinking of using pure functions, but I have not been able to figure out my way through it.

$\endgroup$

closed as unclear what you're asking by m_goldberg, MarcoB, user9660, dr.blochwave, Silvia Oct 26 '15 at 9:16

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ If you look at Nc, you will see that it contains only terms of the form c[i,j,t], it contains no terms of the form s[i]. I suspect that your table has not done what you intended. $\endgroup$ – bill s Oct 25 '15 at 17:31
1
$\begingroup$

Here is a possible approach illustrated in a simplified system. First define s[i] as desired

Nc := Sum[c[i, t], {i, 2}]
s[i_] := (i/Nc)^2

and then create, solve, and plot the system of ODEs.

eqs = Table[D[c[i, t], t] == s[i] c[i, t], {i, 2}];
var = Table[c[i, t], {i, 2}];
sol = NDSolveValue[{eqs, Thread[var == 1] /. t -> 0}, var, {t, 0, 2}];
Plot[sol, {t, 0, 2}, AxesLabel -> {t, c}]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.