5

I have to sketch the direction field for the following differential equation:

$$\frac{dy}{dx}=\frac{-0.02 y +0.00002 xy}{0.08 x-0.001xy}$$

This is the code I used, which gives an incorrect plot:

StreamPlot[Normalize[{1, (y (-0.016 + 0.00008 x))/(x (0.12 - 0.006 y))}], 
    {x, -200, 200}, {y, -200, 200}, Axes -> True]

The following picture shows what I need to get:

enter image description here

Sascha
  • 8,459
  • 2
  • 32
  • 66
Maggie
  • 93
  • 5
  • I think this is duplicate http://mathematica.stackexchange.com/questions/8841/how-can-i-plot-the-direction-field-for-a-differential-equation "How can I plot the direction field for a differential equation?" – Nasser Sep 19 '13 at 00:20
  • @Nasser The user has already tried StreamPlot as shown there and says the result is incorrect, so I don't think it is a duplicate outright. Thanks for looking for duplicates however! – Mr.Wizard Sep 19 '13 at 00:22
  • data = Table[{1, dyx}, {x, 1, 3000, 10}, {y, 1, 150}]; ListStreamPlot[data] comes close. I'm not saying it's an answer, just 'closer'. –  Sep 19 '13 at 03:31

3 Answers3

9

I think the following is a bit closer

f[x_, y_] := (-0.02 y + 0.00002 x y)/(0.08 x - 0.001 x y)
{X1, X2} = {0, 3100};
{Y1, Y2} = {0, 150};
AR = 0.5;
length = 0.04;
VectorPlot[{1, f[x, y]}, {x, X1, X2}, {y, Y1, Y2}, AspectRatio -> AR, 
 PlotRange -> {{X1, X2}, {Y1, Y2}}, VectorStyle -> Arrowheads[{}], 
 VectorScale -> {length, Automatic, If[#5 > 0, #5/Sqrt[#3^2 + (AR(X1-X2)#4/(Y1-Y2))^2],0] &}]

enter image description here

This solution gives the equal lengths of the arrows with taking into account the aspect ratio.

ybeltukov
  • 43,673
  • 5
  • 108
  • 212
  • The lines above/below (250, 80) look shorter to me. I think you want #5/Sqrt[..] inside the If in VectorScale. See http://mathematica.stackexchange.com/questions/103179/how-to-adjust-vector-scaling-with-a-specific-aspect-ratio/103180#103180 – Michael E2 Jan 01 '16 at 23:22
  • @MichaelE2 You are right, thanks. – ybeltukov Jan 02 '16 at 13:47
6

I'll assume that what you really want is a StreamPlot and not a vector plot, because that's in your code.

The equation you're plotting in the question isn't the one in the first equation. But even if we correct this, the StreamPlot looks bad because it cuts off the automatically generated streamlines before they are long enough to outline the shape of the slope field.

To remedy this, you can try specifying a minimum length for the streamlines, and also choose them to go through the interesting points in the plot. I've taken your (corrected) StreamPlot and added the necessary StreamPoints option:

StreamPlot[
 Normalize[{1, (-0.02 y + 0.00002 x y)/(0.08 x - 
      0.001 x y)}], {x, 0, 3000}, {y, 0, 150}, Axes -> True, 
 StreamPoints -> {Table[{1040, i}, {i, 13, 150, 5}], Automatic, 3000},
  PlotRange -> All]

swirl

Jens
  • 97,245
  • 7
  • 213
  • 499
3

I believe this is getting close to what you want:

f[x_, y_] := (-0.02 y + 0.00002 x y)/(0.08 x - 0.001 x y)

VectorPlot[{1, f[x, y]}, {x, 0, 3100}, {y, 0, 150}, VectorStyle -> Arrowheads[{}]]

enter image description here

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • VectorPlot is addressed in the post that Nasser linked to... besides, OP's main fault is plotting a different equation than the one that they actually want! – rm -rf Sep 19 '13 at 00:57
  • @rm-rf Oh, well I guess we can delete this in a little while then. – Mr.Wizard Sep 19 '13 at 00:58
  • VectorPlot[{5 , f[x, y]}, {x, 0, 3100}, {y, 0.1, 150}, PlotRange -> {{0, 3100}, {0, 150}}, VectorScale -> .03] is a little more aligned with the OP's plot – Dr. belisarius Sep 19 '13 at 01:04
  • By the way, how to get arrows with the equal lengths? Because of the large aspect ratio (3100/150), they always have different lengths... – ybeltukov Sep 19 '13 at 01:05
  • @ybeltukov I'll admit I tried for a few minutes to get that (I was using VectorScale) but I failed. I intend to return to it later. Let me know if you figure it out before I do! – Mr.Wizard Sep 19 '13 at 01:11
  • @Mr.Wizard If you do not mind, I put it as a separate answer. – ybeltukov Sep 19 '13 at 01:46
  • @ybeltukov Of course, I do not mind. What you did was definitely the harder part of the answer. – Mr.Wizard Sep 19 '13 at 05:12