I've been trying to plot the radial vector field given by a point charge. The basic shape of the field is very easy to obtain, given by:

VectorPlot[{x, y}, {x, -5, 5}, {y, -5, 5}].

However this does not take into account the fact that the strength of the electric field drops of proportional to $\frac{1}{r^2}$ (where $r$ is the radial distance from the charge), giving vectors which increase in magnitude as you vary further from the charge.

I would like to scale the vectors so that their magnitude drops off as a function of $\frac{1}{r^2}$; I know it will involve VectorScale, however am new to how to use it exactly.

  • $\begingroup$ VectorPlot[{x, y}/(x^2+y^2), {x, -5, 5}, {y, -5, 5}]? $\endgroup$ – yohbs Sep 10 '17 at 12:03
  • $\begingroup$ What you're plotting is proportional to the field of a point charge times $r^3$ . The correct electric field is proportional to {x,y}/(x^2+y^2)^(3/2). $\endgroup$ – jjc385 Sep 10 '17 at 12:05
  • $\begingroup$ @yohbs The (unit) direction is {x,y}/Sqrt[x^2+y^2], so you need an extra factor of $1/r$. $\endgroup$ – jjc385 Sep 10 '17 at 12:06
  • $\begingroup$ @aidangallagher4 You'll also need to deal with the fact that the field diverges at the origin. See e.g. this question. $\endgroup$ – jjc385 Sep 10 '17 at 12:07
  • $\begingroup$ Thanks @jjc385, write a brief answer and I'll mark as answered. $\endgroup$ – aidangallagher4 Sep 10 '17 at 12:20

Getting the field right

There are two issues involved:

  • The magnitude of your vector needs to be (proportional to) $\frac{1}{r^2}$
  • You need to multiply the magnitude by the unit direction

The unit direction is {x,y}/(x^2+y^2)^(1/2).

Scaling by the magnitude of 1/(x^2+y^2), you obtain

electricField = {x,y}/(x^2+y^2)^(1/2)

Getting the plot right

(This issue is essentially a duplicate of this question. What follows is borrowed heavily from the answers there.)

Naively you'd write

Plot[electricField, {x, -5, 5}, {y, -5, 5}]

but since the field diverges at the origin, this is nearly useless.

Instead, you can do

   If[x^2 + y^2 > 0.2, electricField, 0], 
   {x, -5, 5}, {y, -5, 5},
   RegionFunction -> Function[{x, y}, x^2 + y^2 > 0.2]

Fixed vector plot

  • The RegionFunction tells VectorPlot to ignore points close to the origin
  • The If statement, while seemingly redundant, makes sure VectorPlot doesn't put an extraneous vector at the origin.

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