TransWikia.com

Want to vary the parameters of system of differential equations in a Manipulate

Mathematica Asked by Diana zapata on March 2, 2021

I have a system of differential equations. I want to vary all the parameters, but the code shown below doesn’t work for me. Could someone help me? I’m barely learning.

This is my code:

  DynamicModule[{eqns, init, sol, H, L, F, Z, S, P, t}, 
  Manipulate[eqns = {H'[t] =gamma1 (k1 F[t] + q1 K2 P[t])/(F[t] + 
lambda ) P[t])-(1 - q2) gamma1 P[t](delta1+eta1) H[t], 
L'(t)=eta1 H[t] (1- (L[t]+S[t])/(B))-L[t](tau1+epsilon1)L[t],
F'[t]=p1 tau1 L[t]-mu1 F[t],
Z'(t)=gamma2 q_2 P[t]-(delta2+eta2) Z[t],
S'[t]=eta2 Z[t] (1-(L[t]+S[t])/B))-S[t] (tau2+epsilon2),
P'[t]=p2 tau2 [t]-mu2 [t]};

init = {H[0] == H0, L[0] == L0, F[0] == F0, Z[0] == Z0, S[0] == S0, 
P[0] == P0};
sol = NDSolve[{eqns, init}, {H, L, F, Z, S, P}, {t, 0, 300}];
Plot[Evaluate[{H[t], L[t], F[t], Z[t], S[t], P[t]} /. sol], {t, 0,    300},

PlotLegends ->   Placed[{"H", "L", "F", "Z", "S", "P"}, Scaled[{0.9, 0.9}]]], 
{{B,   1}, 0, 1200}, {{gamma1, 1}, 0, 2},{{gamma2,1},0,2},{{eta 
1,1},0,2},{{eta2,1},0,2},{{delta1 ,1},0,2}, {{delta2,1},0,2},{{tau 
1,1},0,2},{{tau2,1},0,2},{{epsilon1,1},0,2},{{epsilon2,1},0,2}, 
{{p1,1},0,2},{{p2,1},0,2},{{mu1,1},0,2},{{mu2,1},0,2},{{k1,1},0,2},
{{k2,1},0,2},{{q1,1},0,2},{{q2,1},0,2},

Delimiter,   "initial conditions", {{H0, 0.5}, 0, 1}, {{L0, 0}, 0, 1}, {{F0, 
1}, 0, 1}, {{Z0, 1}, 0, 1}, {{S0, 1}, 0, 1}, {{P0, 1}, 0, 1}]]

enter image description here

This is what appears to me:

enter image description here

One Answer

To be frank, your code is a mess. Full of syntax errors. But even when thesse are corrected, your system of ODEs doesn't have solutions over the full ranges of the given parameters. Also, lambda isn't defined.

I was able to correct the syntax errors and assign an arbitrary value to lambda. For your ODE problems, I just added some error checking, so the code would run. It would take knowledge of the problem domain that I don't have to tackle that. You will have to work it out yourself, but at least this answer will provide you with a base from which you can move ahead.

With[{lambda = .5},
  DynamicModule[{eqns, init, solns, H, L, F, Z, S, P, t},
    Manipulate[
      eqns =
        {H'[t] == 
           gamma1 (k1 F[t] + q1 k2 P[t])/(F[t] + lambda) P[t] - 
             (1 - q2) gamma1 P[t] (delta1 + eta1) H[t], 
         L'[t] == 
         eta1 H[t] (1 - (L[t] + S[t])/B) - L[t] (tau1 + epsilon1) L[t], 
         F'[t] == p1 tau1 L[t] - mu1 F[t], 
         Z'[t] == gamma2 q2 P[t] - (delta2 + eta2) Z[t], 
         S'[t] == eta2 Z[t] (1 - (L[t] + S[t])/B) - S[t] (tau2 + epsilon2), 
         P'[t] == p2 tau2[t] - mu2[t]};
      init = 
        {H[0] == H0, L[0] == L0, F[0] == F0, Z[0] == Z0, S[0] == S0,P[0] == P0};
      solns =
        Quiet @ Check[
          NDSolveValue[{eqns, init}, {H, L, F, Z, S, P}, {t, 0, 300}], $Failed];
      If[solns === $Failed,
        "No solution for current settings",
        {HF, LF, FF, ZF, SF, PF} = solns;
        Plot[{HF[t], LF[t], FF[t], ZF[t], SF[t], PF[t]}, {t, 0, 300},
          PlotRangePadding -> {Automatic, {Automatic, Scaled[.5]}},
          PlotLegends ->
            Placed[
              {"H", "L", "F", "Z", "S", "P"}, 
              Scaled[{.9, .9}]]]], 
      {{B, 1}, 1, 1200},
      {{gamma1, 1}, 0, 2},
      {{gamma2, 1}, 0, 2},
      {{eta1, 1}, 0, 2},
      {{eta2, 1}, 0, 2},
      {{delta1, 1}, 0, 2},
      {{delta2, 1}, 0, 2},
      {{tau1, 1}, 0, 2},
      {{tau2, 1}, 0, 2},
      {{epsilon1, 1}, 0, 2},
      {{epsilon2, 1}, 0, 2},
      {{p1, 1}, 0, 2},
      {{p2, 1}, 0, 2},
      {{mu1, 1}, 0, 2},
      {{mu2, 1}, 0, 2},
      {{k1, 1}, 0, 2},
      {{k2, 1}, 0, 2},
      {{q1, 1}, 0, 2},
      {{q2, 1}, 0, 2},
      Delimiter,
      "initial conditions",
      {{H0, 0.5}, 0, 1},
      {{L0, 0}, 0, 1},
      {{F0, 1}, 0, 1},
      {{Z0, 1}, 0, 1},
      {{S0, 1}, 0, 1},
      {{P0, 1}, 0, 1}]]]

demo

Answered by m_goldberg on March 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP