Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.7K Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Unexpected output from VectorPlot[ ] of a forcefield

Posted 3 years ago

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

Attachments:
POSTED BY: Herwig Wachter
4 Replies
Posted 3 years ago

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}]

enter image description here

POSTED BY: Rohit Namjoshi

Hi,

I get this when I run your code:

enter image description here

which is what I would expect.

Cheers, Marco

POSTED BY: Marco Thiel

You forgot the underscores to define a function: r2[x_, y_] = x^2 + y^2.

POSTED BY: Gianluca Gorni
Posted 3 years ago

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.

POSTED BY: Herwig Wachter
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard