2
$\begingroup$

Im trying to plot x[t] and y[t] but I dont know which parts of my code is wrong. Can anybody help me?

here is my code:

G1 = k m p - (1 + k) p s + s (-c + e - (1 + k) p r - (k A)/B)
G2 = (500 + e - h - (1 + k) p) s
G3 = k m p - (1 + k) p s + s (-c - (k A)/B)
G4 = -h s
C1 = -k m p + (1 + k) p s + s ((1 + k) p r - w)
C2 = s (p - w)
C3 = -k m p + (1 + k) p s
C4 = 0
UG1[t_] := y[t] (G1) + (1 - y[t]) (G3)
UG2[t_] := y[t] (G2) + (1 - y[t]) (G4)

UC1[t_] := x[t] (C1) + (1 - x[t]) (C2)
UC2[t_] := x[t] (C3) + (1 - x[t]) (C4)
sol = ParametricNDSolveValue[{x'[t] == 
    x[t] (1 - x[t]) (UG1[t] - UG2[t]), 
   y'[t] == y[t] (1 - y[t]) (UC1[t] - UC2[t]), y[0] == 0.25, 
   x[0] == 0.2}, {x, y}, {t, 0, 1}, {p, r, w, e, c, s, h, B, A, m}]
Manipulate[
 Plot[Evaluate[#[t] & /@ sol[p, r, w, e, c, s, h, B, A, m]], {t, 0, 
   0.01}, PlotLegends -> {x, y}], {{p, 100}, 50, 500}, {{r, 5}, 0, 
  10}, {{w, 2000}, 100, 10000}, {{e, 600}, 100, 5000}, {{c, 300}, 50, 
  1000}, {{s, 1}, 1, 300}, {{h, 900}, 100, 5000}, {{B, 5}, 1, 
  30}, {{A, 10000}, 100, 100000}, {{m, 350}, 50, 1000}]

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

You were missing k value. Also you need to set the parameters correctly in Manipulate and add TracedSymbols, etc...

Mathematica graphics

Code

Clear["Global`*"];
G1 = k m p - (1 + k) p s + s (-c + e - (1 + k) p r - (k A)/B);
G2 = (500 + e - h - (1 + k) p) s;
G3 = k m p - (1 + k) p s + s (-c - (k A)/B);
G4 = -h s;
C1 = -k m p + (1 + k) p s + s ((1 + k) p r - w);
C2 = s (p - w);
C3 = -k m p + (1 + k) p s;
C4 = 0;
UG1[t_] := y[t] (G1) + (1 - y[t]) (G3);
UG2[t_] := y[t] (G2) + (1 - y[t]) (G4);

UC1[t_] := x[t] (C1) + (1 - x[t]) (C2);
UC2[t_] := x[t] (C3) + (1 - x[t]) (C4);
eqs = {x'[t] == x[t] *(1 - x[t])* (UG1[t] - UG2[t]),
   y'[t] == y[t] (1 - y[t]) (UC1[t] - UC2[t])};
sol = ParametricNDSolveValue[{eqs, y[0] == 0.25, x[0] == 0.2}, {x, 
   y}, {t, 0, 1}, {p, r, w, e, c, s, h, B, A, m, k}]

Mathematica graphics

Manipulate[
 Module[{sol0},
  sol0 = sol[p0, r0, w0, e0, c0, s0, h0, B0, A0, m0, k0];
  Plot[Evaluate[#[t] & /@ sol0], {t, 0, 0.01}, PlotLegends -> {x, y}]
  ]
 ,
 {{p0, 100}, 50, 500, Appearance -> "Labeled"},
 {{r0, 5}, 0, 10, Appearance -> "Labeled"},
 {{w0, 2000}, 100, 10000, Appearance -> "Labeled"},
 {{e0, 600}, 100, 5000, Appearance -> "Labeled"},
 {{c0, 300}, 50, 1000, Appearance -> "Labeled"},
 {{s0, 16}, 1, 300, Appearance -> "Labeled"},
 {{h0, 900}, 100, 5000, Appearance -> "Labeled"},
 {{B0, 5}, 1, 30, Appearance -> "Labeled"},
 {{A0, 10000}, 100, 100000, Appearance -> "Labeled"},
 {{m0, 350}, 50, 1000, Appearance -> "Labeled"},
 {{k0, 4}, 4, 1000, Appearance -> "Labeled"},
 TrackedSymbols :> {p0, r0, w0, e0, c0, s0, h0, B0, A0, m0, k0}
 
 ]
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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