3D Equipotential and electric field lines due to point charges
Takao Takeuchi, Ph.D. Department of Mathematics and Physics State University of New York at Alfred Alfred, New York 14802 USA takeuct@alfredstate.edu http://web.alfredstate.edu/takeuchi/index.htm ? 2006 Takao Takeuchi
Introduction
This worksheet demonstrates the use of Maple for calculating and displaying three dimensional equipotential surfaces and electric field lines due to point charges of your choice. It takes quite a long time to plot electric field lines if your computer's cpu is slow. Please modify at your own risk. Try with only two charges first to learn how to use it.Be sure to input reasonable coordinates and charges.
Ver. 9.5.1
Initialization
Input1
The procedure below obtains plotting area size and calls subroutines InputXYZQ and CheckInput.
InputXYZQ
The procedure below obtains coordinates and charge of each charge from the user.
DrawCharge
The procedure below creates a plot structure of the charges.
for i from 1 to Nocharge do if Q[i]>0.0 then charge[i]:=(sphere([xx[i],yy[i],zz[i]],Chargesize,color=blue)); elif Q[i]<0.0 then charge[i]:=(sphere([xx[i],yy[i],zz[i]],Chargesize,color=red)); else charge[i]:=(sphere([xx[i],yy[i],zz[i]],Chargesize,color=yellow)); end if; end do; Chargeall:=seq(charge[i],i=1..Nocharge);
CheckInput
The procedure below checks for duplicate charges.
CalculateV
The procedure below computes potential V at (x,y,z) due to the charges.
MinMaxV
The procedure below computes maxmum and minimum potential due to the charges.
CalculateE
Display3dContoursOfV
The procedure below displays equipotential surfaces or electric field lines.
PlotEfieldLines
The procedure below generates electric field lines, plot structures and display them..
GetOneEfieldLineSegment
The procedure below creates one electric field line.
if R<>0.0 then Ex:=Ex+Q[i]*Rx/R3; Ey:=Ey+Q[i]*Ry/R3; Ez:=Ez+Q[i]*Rz/R3; end if; end do; E:=sqrt(Ex^2+Ey^2+Ez^2); if E<>0.0 then H1:=s*Ex/E; H2:=s*Ey/E; H3:=s*Ez/E; end if; x1:=x1+H1; y1:=y1+H2; z1:=z1+H3; if ((abs(H1+H1N)<smallinc and abs(H2+H2N)<smallinc and abs(H3+H3N)<smallinc)) or Ntime=600 then EfieldLineSegment[segno]:=seq(LineSegment[n],n=1..Ntime-1); break; end if; for j from 1 to Nocharge do if ((abs(x1-xx[j])+abs(y1-yy[j])+abs(z1-zz[j]))<abs(0.9*s)) then EfieldLineSegment[segno]:=seq(LineSegment[n],n=1..Ntime-1); break; end if; end do; if (x1>=xmax or x1<=xmin or y1>=ymax or y1<=ymin or z1>=zmax or z1<=zmin) then EfieldLineSegment[segno]:=seq(LineSegment[n],n=1..Ntime-1); break; end if; LineSegment[Ntime]:=line([xN,yN,zN],[x1,y1,z1]); Ntime:=Ntime+1; # printf ("k= %d and Ntime= %d", k, Ntime); xN:=x1:yN:=y1;zN:=z1; H1N:=H1;H2N:=H2;H3N:=H3 end do; # k loop # printf ("k final= %d and Ntime= %d", k, Ntime);print (xmin); end proc:
Main Procedure
Important! You have to run both
1. Input1
2. Display3dContoursOfV
Input1(xmin,xmax,ymin,ymax,zmin,zmax)
xmin, xmax : Window size in x direction Use number like -1.5, 1.5 ymin, ymax : Window size in y direction Use number like -2, 2
zmin, zmax : Window size in z direction Use number like -2, 2 Input charges Number of charges: number of charges you want to consider. Use 1, 2, 3, etc. XX(i): x coordinate of the i-th charge Use numbers like 1, -1 etc. YY(i): y coordinate of the i-th charge Use numbers like 1, -1 etc. ZZ(i): z coordinate of the i-th charge Use numbers like 1, -1, etc. Q(i): charge of i-th charge Use numbers like 1, -2, 3, etc.
Important! Be sure to type a semicolon ";" after typing in an input number in ver. 9.5.1. But in ver.10, type a number and press return.
Diplay3dContoursOfV(potflag) potflag=0 : Electric field lines will be plotted around all charges 1 : Equipotential surfaces 2 : Electric field lines will be plotted around one charge of your choice *********************************************************************** Reference: J.R. Merrill, "Using Computers in Physics", p.45, 1976, Houghton Mifflin Comp., Boston ***********************************************************************
Example
For charge 1
Vmin = -2.220633E+00, Vmax = 1.000000E-30
Example output
Legal Notice: The copyright for this application is owned by the author(s). Neither Maplesoft nor the author are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application in for-profit activities.