0
$\begingroup$

I have the following system of linear ODEs for "i" number of species "c" migrating in "j" number of habitats:

eq1 = Table[D[c[i, j, t], t] == q - (s[i] + d[j]) c[i, j, t], {i, 1, 5}, {j, 1, 1}];

eq2 = Table[D[c[i, j, t], t] == s[i] c[i, j - 1, t] - (s[i] + d[j]) c[i, j, t], {i, 1, 5}, {j, 2, 9}];

eq3 = Table[D[c[i, j, t], t] == s[i] c[i, j - 1, t] - d[j] c[i, j, t], {i, 1, 5}, {j, 10, 10}];

initCon = Table[c[i, j, 0] == 0,{i, 1, 5}, {j, 1, 10}];

sol = DSolve[{eq1, eq2, eq3, initCon}, Flatten@Table[c[i, j, t], {i, 1, 5}, {j, 1, 10}], t];

(* for i=5 and j=10 *)
h = 4;
hd = 4;
m = 0.5;
d[0] = 0.05;
di = 0.2;
q = 100000;
s[i_] := (m + m i)/2;
d[j_] := d[0] + (di*j)/(hd + j);

so I can evaluate the population size and plot it as a histogram against j

BarChart[Evaluate[Table[Sum[c[i, j, t], {i, 1, 5}], {j, 1, 10}] /. sol /. t -> 100]

Now, I have a function f which also depends on j,

f= 1000 (j/j+h)

I want to plot population size as histogram against f now, given the relationship between f and j.

Thanks in advance for the help!

$\endgroup$
6
  • $\begingroup$ once you have computed Total (you should not use a capital T for your own symbol by the way ) it is a function of t only. As there is no more j in the expression the last bit doesn't make any sense. Perhaps you meant to just sum over i ? $\endgroup$
    – george2079
    Commented Dec 2, 2015 at 20:22
  • $\begingroup$ @george2079 I have made some changes in the question for better understanding. Please go through them and help me! $\endgroup$
    – VitalSigns
    Commented Dec 4, 2015 at 6:58
  • $\begingroup$ @Xavier I have made some changes in the question for better understanding. Please go through them and help me! $\endgroup$
    – VitalSigns
    Commented Dec 4, 2015 at 6:58
  • $\begingroup$ it would be best if you provide a minimal working example. In your code c, s and other functions are not defined. Anyway, I'm not sure I understand your problem, but can't you just invert your last equation expliciting j as a function of f, and than use BarChart to plot against that? $\endgroup$
    – glS
    Commented Dec 4, 2015 at 7:09
  • $\begingroup$ @glS tried that... but doesn't work for non-integer values of j and specially if you have a non-linear relationship between j and f values of j $\endgroup$
    – VitalSigns
    Commented Dec 4, 2015 at 7:21

1 Answer 1

1
$\begingroup$

Now it makes sense: Just add your f to each table item: (added parenthesis required, else you just have 1+h )

 Evaluate[Table[{1000. (j/(j + h)), 
       Sum[c[i, j, t] /. (First@sol), {i, 1, 5}]}, {j, 1, 10}] /. 
            t -> 100]

{{200., 517802.219885}, {333.333, 449216.620639}, {428.571, 382758.770615}, {500., 322594.11367}, {555.556, 273802.994}, {600., 297371.4}, {636.364, 1.34096*10^6}, {666.667, 1.7341*10^7}, {692.308, 2.1090*10^8}, {714.286, -2.762*10^72}}

Your totals vary by many orders of magnitude, so a simple plot of this is meaningless.

Here is a Log plot.. note even on the log scale the last point is really big.

ListPlot[Evaluate[
  Table[{1000. (j/(j + h)), 
     Log@Abs@Sum[c[i, j, t] /. (First@sol), {i, 1, 5}]}, {j, 1,10}] /. t -> 100]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks! I realize how stupid the querry was .) $\endgroup$
    – VitalSigns
    Commented Dec 15, 2015 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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