Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

My aim is to plot a vector field of the following system with a few trajectories:

$$r'(t)=i-l.r(t)-\text{ux}. r(t). x(t)-\text{uy}. r(t). y(t) \\ x'(t)=\text{ex}. \text{ux}. r(t). x(t)-\text{mx}. x(t)\\y'(t)=\text{ey}.\text{uy}. r(t). y(t)-\text{my}. y(t)$$

$i,l,ux,uy,mx,my,ex,ey$ are parameters.

Here is what I have managed to do so far:

Manipulate[
  ParametricPlot3D[
    Evaluate[
      {r[t], x[t], y[t]} /. 
        NDSolve[{
          r'[t] == i - l*r[t] - ux*r[t]*x[t] - uy*r[t]*y[t], 
          x'[t] == -mx*x[t] + ex*ux*r[t]*x[t], 
          y'[t] == -my*y[t] + ey*uy*r[t]*y[t], 
          r[0] == 1, x[0] == 1, y[0] == 1}, 
          {r, x, y}, {t, 0, 100000}, 
          MaxSteps -> Infinity, 
          AccuracyGoal -> 10]], 
    {t, 0, 10000}, 
    PlotRange -> Full, 
    AxesLabel -> {"r(t)", "x(t)", "y(t)"}, 
    PlotStyle -> {Green, Thickness[0.01]}], 
  {i, 0, 100}, 
  {l, 0, 1}, 
  {ux, 0, 1}, 
  {uy, 0, 1}, 
  {mx, 0, 1}, 
  {my, 0, 1}, 
  {ex, 0, 1}, 
  {ey, 0, 1}]

This plot one trajectory and it works fine (although you might not think so looking at it but it is due to the equations.

Then when I tried to plot the vector field alone and I got stuck.I do not know what is going wrong:

Manipulate[
  VectorPlot3D[
    Evaluate[
      {r[t], x[t], y[t]} /. 
        NDSolve[{
          r'[t] == i - l*r[t] - ux*r[t]*x[t] - uy*r[t]*y[t], 
          x'[t] == -mx*x[t] + ex*ux*r[t]*x[t], 
          y'[t] == -my*y[t] + ey*uy*r[t]*y[t], 
          r[0] == 1, x[0] == 1, y[0] == 1}, 
          {r, x, y}, {t, 0, 100000}, 
          MaxSteps -> Infinity, 
          AccuracyGoal -> 10]], 
    {r[t], 0, 100}, {x[t], 0, 100}, {y[t], 0, 100}, 
    VectorColorFunction -> "DeepSeaColors"], 
  {i, 0, 100}, 
  {l, 0, 1}, 
  {ux, 0, 1}, 
  {uy, 0, 1}, 
  {mx, 0, 1}, 
  {my, 0, 1}, 
  {ex, 0, 1}, 
  {ey, 0, 1}]

The next thing to do was to plot both the vector field and trajectories on the same plot, I have not tried as I could manage to plot the vector field, so if you can give me any piece of advice about this too, I would be extremely grateul. For 2D, without using Manipulate, I used Show but I guess it will not work if I use Manipulate as I need to make the parameters vary simultaneously for the vector field and the trajectories.

(Do not expect any fancy trajectories with these equations, you can change them to have nicer things, I just would like the general way how plotting this for any system of three equations).

EDIT:

THE TWO ANSWERS BELOW GIVE DIFFERENT THINGS SO I DO NOT KNOW WHAT TO DO.

share|improve this question

2 Answers 2

When one talks about vector fields, it usually helps to define what the field is. In your case of a first-order system of equations, I interpret "vector field" simply as the right-hand side of the equations. Therefore, there is no need to use NDSolve, and the parameter t is irrelevant.

Instead, you would do this:

Manipulate[
 VectorPlot3D[
  {i - l*r - ux*r*x - uy*r*y, -mx*x + ex*ux*r*x, -my*y + 
     ey*uy*r*y}, {r, 0, 100}, {x, 0, 100}, {y, 0, 100}, 
  VectorColorFunction -> "DeepSeaColors"], {i, 0, 100}, {l, 0, 
  1}, {ux, 0, 1}, {uy, 0, 1}, {mx, 0, 1}, {my, 0, 1}, {ex, 0, 1}, {ey,
   0, 1}]

vectorfield

share|improve this answer

You can't use VectorPlot3D if the independent variable is the same. t in your case. You'll get errors such as

VectorPlot3D::glims: Range specifications {t,0,100} and {t,0,100} \ 
contain the same iteration variable.

So, without knowing what you are trying to do here, I replaced t to new independent variable for each one of your solutions x,r,y just to make VectorPlot3D happy now you can now use VectorPlot3D.

And it really helps to break the steps out to see what is going on. Instead of writing f[g[y[...]]]] and then wondering where is the problem, one can write

result = y[..]
result = g[result]
result = f[result]

and put each step in separate cell, then you can see more easily see in which step the problem was and correct it.

Manipulate[

 Module[{sol, t, x, r, y, r1, x1, y1},
  sol = First@NDSolve[{
      r'[t] == i - l*r[t] - ux*r[t]*x[t] - uy*r[t]*y[t],
      x'[t] == -mx*x[t] + ex*ux*r[t]*x[t],
      y'[t] == -my*y[t] + ey*uy*r[t]*y[t],
      r[0] == 1, x[0] == 1, y[0] == 1}, {r[t], x[t], y[t]}, {t, 0, 
      1000}, MaxSteps -> Infinity, AccuracyGoal -> 10];

  r = (r[t] /. sol) /. t -> r1;
  x = (r[t] /. sol) /. t -> x1;
  y = (r[t] /. sol) /. t -> y1;

  VectorPlot3D[{r, x, y}, {r1, 0, 1000}, {x1, 0, 1000}, {y1, 0, 1000},
    VectorColorFunction -> "DeepSeaColors"]      
  ],

 {i, 0, 100}, {l, 0, 1}, {ux, 0, 1},
 {uy, 0, 1}, {mx, 0, 1}, {my, 0, 1}, {ex, 0, 1}, {ey, 0, 1}
 ]

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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