5
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ I think this is duplicate mathematica.stackexchange.com/questions/8841/… "How can I plot the direction field for a differential equation?" $\endgroup$
    – Nasser
    Sep 19, 2013 at 0:20
  • $\begingroup$ @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! $\endgroup$
    – Mr.Wizard
    Sep 19, 2013 at 0:22
  • $\begingroup$ 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'. $\endgroup$
    – user9444
    Sep 19, 2013 at 3:31

3 Answers 3

3
$\begingroup$

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

$\endgroup$
7
  • $\begingroup$ 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! $\endgroup$
    – rm -rf
    Sep 19, 2013 at 0:57
  • $\begingroup$ @rm-rf Oh, well I guess we can delete this in a little while then. $\endgroup$
    – Mr.Wizard
    Sep 19, 2013 at 0:58
  • $\begingroup$ 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 $\endgroup$ Sep 19, 2013 at 1:04
  • $\begingroup$ By the way, how to get arrows with the equal lengths? Because of the large aspect ratio (3100/150), they always have different lengths... $\endgroup$
    – ybeltukov
    Sep 19, 2013 at 1:05
  • $\begingroup$ @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! $\endgroup$
    – Mr.Wizard
    Sep 19, 2013 at 1:11
9
$\begingroup$

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.

$\endgroup$
2
6
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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