7.120 bug in plotting electric field of a dipole in Maple V.2 (24.10.97)

7.120.1 J. David Wright
7.120.2 Michael Komma (28.10.97)
7.120.3 Robert Israel (28.10.97)
7.120.4 Michael Komma (28.10.97)

7.120.1 J. David Wright

I would like to plot the electric field of a dipole using Maple V RII for the macintosh.

A simplified vector form for the electric field of a dipole is:

[2*cos(theta)/r^3,sin(theta)/r^3]
 

As a first attempt I tried the following:

> Edipole:=[2*cos(theta)/r^3,sin(theta)/r^3]; 
> fieldplot( Edipole,r=-10..10,theta=0..Pi,coords=polar); 
Error, (in plot/options2d) unknown or bad argument, coords = polar
                                                                                    
                                                                                    
 

That method obviously didn’t work and I couldn’t figure out how to make a plot directly from the polar coordinates.

Then I tried transforming to cartesian coordinates.

>Edipole:=subs({r=(x^2+y^2)^(1/2),theta=arctan(y/x)}, 
                [2*cos(theta)/r^3,sin(theta)/r^3]); 
> fieldplot( Edipole,x=-10..10,y=-10..10);
 

This method produced a plot but it did not look like a typical textbook picture of a dipole’s electric field.

Then I tried to plot the gradient of the electric potential of a dipole

> Vdipole:=subs({r=(x^2+y^2)^(1/2),theta=arctan(y/x)},cos(theta)/r^2); 
> gradplot( Vdipole,x=-10..10,y=-10..10);
 

This method produced a plot which looked exactly like that of the previous method.

I also seem to remember getting ’division by zero' errors as well while trying to use field plot for this particular problem. However, I cannot seem to reproduce such an error at this moment.

I wonder how one generally deals with ’division by zero’ errors in plotting routines.

Further, I would appreciate any suggestions concerning plotting the electric field of a dipole.

It is corrected with Maple V.3. (U. Klein)

7.120.2 Michael Komma (28.10.97)

http://userwst1.fh-reutlingen.de/~komma/physth/feldli1.ms

(should be updated, commented and translated ;-)

7.120.3 Robert Israel (28.10.97)

Release 2! I’m using Release 4 right now, but I think my remarks still apply.

| A simplified vector form for the electric field of a dipole is: ...

Release 4 doesn’t produce an error message here, but the result is not correct.

| Then I tried transforming to cartesian coordinates. ...

Three problems here:

1) Since the arrows grow in size as r -> 0, you only get a few big arrows and the rest very tiny. You might try it without the r^3 in the denominator, to at least get the directions if not the magnitudes of the arrows.

2) theta = arctan(y/x) only works in the right half plane. Use the two-variable form theta = arctan(y,x) which works in the whole plane.

3) That’s _not_ the electric field of a dipole! What you want (for the cross-section of a three-dimensional dipole) is [ 3*cos(2*theta)-1, 3*sin(2*theta)]/r^3

| I also seem to remember getting ’division by zero’ errors as well ...

I’ve run into it just now in R4 as well. For example,

> fieldplot([0,0], x = -1 .. 1, y = -1 .. 1); 
Error, (in plots/fieldplot/arrowsf2d) division by zero
 

This is a bug.

| I wonder how one generally deals with ’division by zero’ errors ...

If it comes from arrows of 0 length, try to avoid having arrows of 0 length. If they occur only at a discrete set of points or on a curve, you might shift the x and/or y endpoints a bit to miss these points. Or cheat by adding a small nonzero vector (too small to actually be seen in the plot) to the field.

7.120.4 Michael Komma (28.10.97)

| Error, (in plot/options2d) unknown or bad argument, coords = polar

This option is available in R4.

| Then I tried transforming to cartesian coordinates. ...

Besides the transformation of coordinates you must transform the fieldvector: E[x]=E[r]*cos(theta)-E[theta]*sin(theta), E[y]=E[r]*sin[theta]+E[theta]*cos[theta]

| I wonder how one generally deals with ’division by zero’ errors ...

There are at least two reasons for ’division by zero’.

1. The singularity at r=0: shift the plot ranges, so that this point is not evaluated in the grid (example: -1.001..1.002) or add a small constant in the denominator (1/(r^3+.0001)).

2. If terms in the vector occur, that cannot be evaluated, Maples fieldplot reacts with a ’division by zero’ (due to zero-step-size I guess).

Plotting electrostatic fields (fieldlines) is best done with numerical methods, since the analytical solutions are the exception. The ’few’ closed solutions can be obtained by multipole-expansion of the *potential*.