Plotting radial electric field with VectorPlot [duplicate]

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.

marked as duplicate by MarcoB, LLlAMnYP, LCarvalho, b3m2a1, J. M. is away♦ plotting StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Sep 13 '17 at 2:27

• VectorPlot[{x, y}/(x^2+y^2), {x, -5, 5}, {y, -5, 5}]? – yohbs Sep 10 '17 at 12:03
• 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). – jjc385 Sep 10 '17 at 12:05
• @yohbs The (unit) direction is {x,y}/Sqrt[x^2+y^2], so you need an extra factor of $1/r$. – jjc385 Sep 10 '17 at 12:06
• @aidangallagher4 You'll also need to deal with the fact that the field diverges at the origin. See e.g. this question. – jjc385 Sep 10 '17 at 12:07
• Thanks @jjc385, write a brief answer and I'll mark as answered. – 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.

VectorPlot[

• 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.