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

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}]]


This is what appears to me:

• Please do not post images of your work, especially when the images display at a size that make them difficult to read. Please post your actual Mathematica code in the form of text that can be copied and pasted into a Mathematica notebook. Without such, people who wan to help you will have do a lot of work to reproduce your problem so they can experiment with possible solutions. Jan 26, 2021 at 18:07
• If you are right, for some reason I cannot copy the code and the image did not fit well, I am in the process of improving the publication of the question. Thank you very much for your suggestion, i'm new to this and i'm learning :) Jan 26, 2021 at 23:17
• Ctrl +A and Ctrl+C very easy to me ? Jan 27, 2021 at 14:24
• Your code uses the underscore symbol "_" for variable names -- it must not. Voting to close as a "simple mistake or something that can be found in the documentation." Jan 27, 2021 at 14:25
• @AntonAntonov New contributor has old typos, but m_goldberg answer looks very good. Jan 28, 2021 at 14:06

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},
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}]]]


• I thank you very much for your help, I will continue on this path to see what results I can obtain. I appreciate your understanding and help. Jan 27, 2021 at 16:55
• @Dianazapata. The parameters tau2, mu2 and p2 seem to especially troublesome. There seem to no solutions unless they are fixed at 1; i.e., essentially eliminated. I also it would worth your while to restrict the the t-domain to something like [0, 15]. Jan 27, 2021 at 17:18
• If that was observing that of the parameters, the time must be long term, Thank you very much :), To set those parameters would you have to do it at the top? , i.e With[{lambda = .5, tau2=1,mu=1,p2=1} Jan 28, 2021 at 13:51
• @Dianazapata. Using With to specify parameters with a fixed value generally works well. My suggestion for reducing the domain was only for the temporary purpose of debugging the code. I should have made that clear. Jan 28, 2021 at 15:42