4
$\begingroup$

I try to plot a 2D gravity field or something similar in the form like $r/|r|^3$ with the standart builtin VectorPlot function:

VectorPlot[{-x/(x^2 + y^2)^(3/2), -y/(x^2 + y^2)^(3/2)}, {x, -5, 5}, {y, -5, 5}]

It should look like: what it should look like
(source: euclideanspace.com)

I get something strange when I run my command:

what i get

Any suggestions?

Thanks Cx

$\endgroup$
8
$\begingroup$

You need VectorPoints to be adjusted, also, gravity explodes for point mass so it is good to adjust VectorScale and cut off the point mass with RegionFunction:

VectorPlot[-#/Norm[#]^3 &[{x, y}], {x, -1, 1}, {y, -1, 1}, 
           VectorPoints -> 20, VectorScale -> .3, 
           RegionFunction -> (Norm[{#, #2}] > .1 &), 
           ImageSize -> 500, PlotRange -> 1]

enter image description here

In order to reproduce your plot you need to play with VectorScale 3rd element:

VectorPlot[-#/Norm[#]^3 &[{x, y}], {x, -1, 2}, {y, -1, 1}, VectorPoints -> 30, 
        VectorScale -> {.1, Automatic, (#5)^(1/3) &}, 
        RegionFunction -> (Norm[{#, #2}] > .1 &), ImageSize -> 500, 
        PlotRange -> {{-1, 2}, {-1, 1}}, VectorStyle -> "Pointer", 
        GridLines -> ({#, #} &[Join[Range[-1, 2, .1], {{0, Directive[Thick, Blue]}}]]), 
        Epilog -> {EdgeForm[{Thick, Blue}], Red, Disk[{0, 0}, .05]}, 
        AspectRatio -> Automatic]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks for your answer. But if I apply VectorDensityPlot to the same function argument I get still strange results (no decay). $\endgroup$ – cxkoda Nov 14 '13 at 12:54
  • $\begingroup$ @cxkoda You have to play with ColorFunction the reason is the same. This field is exploding in the center and rescaled values are not different enough on the most of the area. $\endgroup$ – Kuba Nov 14 '13 at 12:59
  • $\begingroup$ I wonder why I haven't thought about that. Now everthing is clear, thank you very much. $\endgroup$ – cxkoda Nov 14 '13 at 13:08
  • $\begingroup$ Can you explain to me how RegionFunction -> (Norm[{#, #2}] > .1 &) works? I know # means slot, but what is it in this case? Replacing them with x and y doesn't work. $\endgroup$ – Cazo May 31 at 21:59
  • $\begingroup$ @Cazo RegionFunction should be a function that will be used like regF[ x, y ] internally, where x, y are coordinates of points. You can write Function[{x,y}, Norm[{x,y}... or you can use slots instead of named arguments: ` Norm[{#, #2}...&`. $\endgroup$ – Kuba Jun 1 at 6:52

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