-3
$\begingroup$

This is the first time I am using Mathematica and I am trying to solve the system of ODE, $\dot x=x(1-x)-\frac{2xy}{y+x}\qquad\dot y=-1.5y+\frac{2xy}{y+x}$

When I used Nsolve or DSolve it gives errors.

enter image description here

Then I tried to find equilibrium points,
enter image description here

Can someone please tell me what I am doing wrong. This is the first time I am using Mathematica.

$\endgroup$
5
  • 5
    $\begingroup$ Please put code as something other people can copy into their Mathematica session, instead of screenshots. $\endgroup$ Apr 7, 2017 at 23:36
  • 1
    $\begingroup$ Try sol = {x[t], y[t]} /. NDSolve[{x'[t]==x[t](1-x[t])-2 x[t] y[t]/(y[t]+x[t]), y'[t]==-3/2 y[t]+2 x[t]y[t]/(y[t]+x[t]), x[0]==1, y[0]==2}, {x[t],y[t]}, {t,0,10}][[1]] and follow that with Plot[sol, {t,0,10}] Then substitute appropriate initial conditions for x[0] and y[0] $\endgroup$
    – Bill
    Apr 8, 2017 at 0:11
  • 1
    $\begingroup$ With respect to the second part of your question, one of the curly brackets is misplaced. Try this instead: Solve[{x[t] (1 - x[t]) - 2 x[t] y[t]/(y[t] + x[t]) == 0, -3/2 y[t] + 2 x[t] y[t]/(y[t] + x[t]) == 0}, {x[t], y[t]}]. $\endgroup$
    – bbgodfrey
    Apr 8, 2017 at 0:23
  • $\begingroup$ @Bill In, {x[t], y[t]} /. NDSolve[{x'[t] == x[t] (1 - x[t]) - 2 x[t] y[t]/(y[t] + x[t]), y'[t] == -3/2 y[t] + 2 x[t] y[t]/(y[t] + x[t]), x[0] == 1, y[0] == 2}, {x[t], y[t]}, {t, 0, 10}][[1]] what does {x[t], y[t]} /. and [[1]] do? When I do it as, solve2 = NDSolve[{x'[t] == x[t] (1 - x[t]) - (2 x[t] y[t]/(y[t] + x[t])), y'[t] == -1.5 y[t] + (2 x[t] y[t]/(y[t] + x[t])), x[0] == 1, y[0] == 2}, {x[t], y[t]}, {t, 0, 10}] why doesn't it give any output? Also, can't I use DSolve $\endgroup$
    – clarkson
    Apr 8, 2017 at 0:53
  • $\begingroup$ To answer your questions, if you leave off both the {x[t],y[t]}/. and [[1]] and look at the output then you will see {{x[t]->stuff1, y[t]->stuff2}} when what Plot needs is {stuff1, stuff2}. Thus the extra bits I added give you what Plot needs. Your solve2 version shows me output, but not in a form that Plot can understand. Look up both /. and -> in the help system, those will really help you. I first tried DSolve, it took so long that I thought it would never finish, I tried multiplying to get rid of denominators, same, I switched to NDSolve and it instantly gave a solution. $\endgroup$
    – Bill
    Apr 8, 2017 at 3:40

1 Answer 1

2
$\begingroup$

To solve your system of ODE's numerically, you need two initial conditions. Here I choose random ones.

Eq1 = x'[t] == x[t]*(1 - x[t]) - 2*x[t]*y[t]/(x[t] + y[t]);

Eq2 = y'[t] == -1.5*y[t] + 2*x[t]*y[t]/(x[t] + y[t]);

sol = NDSolve[{Eq1, Eq2, x[0] == 2, y[0] == 1}, {x[t], y[t]}, {t, 0, 10}];

Plot[Evaluate[{x[t], y[t]} /. sol], {t, 0, 10}, PlotRange -> All]

enter image description here

Solve[{x*(1 - x) - 2*x*y/(x + y) == 0, -1.5*y + 2*x*y/(x + y) == 0}, {x, y}]

Solve::ratnz: Solve was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result.

To get rid of the above warring, use fraction instead of decimal.

Solve[{x*(1 - x) - 2*x*y/(x + y) == 0, Rationalize[-1.5]*y + 2*x*y/(x + y) == 0}, {x, y}]

{{x -> 1/2, y -> 1/6}, {x -> 1, y -> 0}}

$\endgroup$

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.