hwachter
(Herwig Wachter)
1
Hi there
I´d like to plot a vectorfield for a force with inverse square of radius dependency, e.g. gravity. From reasons unclear to me the code
d = 10;
r2[x_, y_] =
x^2 + y^2 ; VectorPlot[{x/r2[x, y], y/r2[x, y]}, {x, -d, d}, {y, -d,
d}, VectorScale -> {Automatic}]
yields this funny result - see pdf.
Help is appreciated, thx
Herwig
forcefield.pdf (19.1 KB)
You forgot the underscores to define a function: r2[x_, y_] = x^2 + y^2.
hwachter
(Herwig Wachter)
3
Hi Gianluca,
actually it is underscored, it is somehow not copied into the text. But also the code d = 10;
VectorPlot[{x/(x^2 + y^2), y/(x^2 + y^2)}, {x, -d, d}, {y, -d, d},
VectorScale -> {Automatic}]
yields the same result. the issue must be something different.
mthiel
(Marco Thiel)
4
Hi,
I get this when I run your code:
which is what I would expect.
Cheers,
Marco
Looks like x and y have preexisting values.
ClearAll[r2, x, y];
r2[x_, y_] := x^2 + y^2
d = 10;
VectorPlot[{x/r2[x, y], y/r2[x, y]}, {x, -d, d}, {y, -d, d}, VectorScale -> {Automatic}]