4
$\begingroup$

I am working with Mathematica to plot a system of Nonlinear ODEs, I did a program but it doesn't work. I don't know exactly where is the problem? If someone kindly can help with a remark or a suggestion. The program is next

b1 = 0.5;
b2 = 0.51;
b3 = 0.01;
b4 = 0.1;
c1 = 0.05;
c2 = 0.1;
delta1 = 0.0001;
delta2 = 0.0001;
delta3 = 0.00001;
alphaa = 0.7;
alphap = 0.7;
alphapc = 0.7;
alphacp = 0.7;
epsilon = 0.00001;
gamma = 1;
psi = 0.01;
xi[x_] = x^2 /(1 + x^2);
F[x_, y_] = alphaa*xi[y/(x + epsilon)];
G[x_, y_] = alphap*xi[y/(x + epsilon)];
H1[x_, y_] = alphapc*xi[y/(x + epsilon)];
H2[x_, y_] = alphacp*xi[x/(y + epsilon)];
H[x_, y_] = H1[x, y] - H2[x, y];
eqns = {a'[t] == 
    gamma*q[t] - (b1 + b2 + delta1)*a[t] + b3 *c[t] + b4 *p[t] - 
     F[a[t], c[t]]*a[t]*c[t] - G[a[t], p[t]]*a[t]*p[t],
   p'[t] == 
    b2*a[t] - (b4 + c1 + delta2)*p[t] - H[c[t], p[t]]*p[t]*c[t] + 
     G[a[t], p[t]]*a[t]*p[t],
   c'[t] == 
    b1*a[t] + c1*p[t] - (b3 + c2 + delta3)*c[t] - 
     H[c[t], p[t]]*p[t]*c[t] + F[a[t], c[t]]*a[t]*c[t] - phi*c[t],
   q'[t] == -gamma*q[t],
   b'[t] == phi*c[t],
   a[0] == 0, p[0] == 0, c[0] == 0, q[0] == 1, b[0] == 0
   };
sol = DSolve[eqns, {a, p, c, d, b}, t]
"eqns/.sol/.{t\[Rule]RandomReal[]}"
Plot[{a[t] /. sol}, {t, 0, 100}]

Thank you in advance

$\endgroup$

1 Answer 1

6
$\begingroup$

There are two main problems in your code:

  1. A typo in your differential equations: phi -> psi
  2. Using the exact DSolve for such a complicated system instead of the numerical solver NDSolve.
eqns = {a'[t] == 
    gamma*q[t] - (b1 + b2 + delta1)*a[t] + b3*c[t] + b4*p[t] - 
     F[a[t], c[t]]*a[t]*c[t] - G[a[t], p[t]]*a[t]*p[t], 
   p'[t] == 
    b2*a[t] - (b4 + c1 + delta2)*p[t] - H[c[t], p[t]]*p[t]*c[t] + 
     G[a[t], p[t]]*a[t]*p[t], 
   c'[t] == 
    b1*a[t] + c1*p[t] - (b3 + c2 + delta3)*c[t] - 
     H[c[t], p[t]]*p[t]*c[t] + F[a[t], c[t]]*a[t]*c[t] - psi*c[t], 
   q'[t] == -gamma*q[t], b'[t] == psi*c[t], a[0] == 0, p[0] == 0, 
   c[0] == 0, q[0] == 1, b[0] == 0};
sol = NDSolve[eqns, {a, p, c, d, b}, {t, 0, 10}];
Plot[{a[t] /. sol}, {t, 0, 10}]

Plot

$\endgroup$
3
  • $\begingroup$ Thank you very much for your answer. I didn't see that the problem can be that. Many kinds regards $\endgroup$ Commented Jul 16, 2021 at 10:43
  • $\begingroup$ @KamalKhalil Deleting a question when it has an answer is really bad practice here. For the future always post a minimal working similar example and never post confidential data/codes. $\endgroup$
    – Hans Olo
    Commented Jul 16, 2021 at 11:10
  • $\begingroup$ @HansOlo Okay I will not do that. Thank you very much! $\endgroup$ Commented Jul 16, 2021 at 11:22

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.