Application Center - Maplesoft

App Preview:

Classroom Tips and Techniques: Electric Field from Distributed Charge

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

Image 

 

Classroom Tips and Techniques: Electric Field from Distributed Charge

Robert J. Lopez

Emeritus Professor of Mathematics and Maple Fellow
Maplesoft
 

 

Introduction 

 

This past summer I was asked if Maple could replicate and complete a solution of the following electrostatics problem. 

 

A line charge of density rho[l] = `+`(`/`(`*`(6.0, `*`(nC)), `*`(m))) is on the z-axis, `and`(`<`(-1.5, z), `<`(z, 1.5)), in meters.  Find E(r, theta, z) everywhere in free space; E(r, theta, z) is the electric field expressed in cylindrical coordinates. 

 

The solution to be replicated is summarized in Table 1. 

 

Cylindrical symmetry about the z-axis implies the field is determined by its values in a plane, taken, for example, as the xz-plane.  With r as the position vector in `*`(`^`(real, 3)), and diff(r(x), x) as the location of the charge, the electric field is given by 

 

 

 

where diff(L(x), x) represents the path of integration along the line of charge.  Since the line charge is constant along the line, we have rho[l, diff(r(x), x)] = rho[l].  The free-space assumption implies `and`(epsilon = epsilon[0], epsilon[0] = `/`(`*`(`*`(8.85, `^`(10, -12)), `*`(F)), `*`(m))).  Symmetry implies r = `+`(`*`(x, `*`(`#mover(mi(.  Hence 

 

`and`(`+`(r(x), `-`(diff(r(x), x))) = `+`(`*`(z(x), `*`(`#mover(mi(  

and 

`*`(`^`(abs(`+`(r(x), `-`(diff(r(x), x)))), 2)) = `+`(`*`(`^`(x, 2)), `*`(`^`(`+`(z(x), `-`(diff(z(x), x))), 2)))  

 

With the charge distribution given by diff(r(x), x) = `*`(z, `*`(`#mover(mi( for `and`(`<`(-1.5, z), `<`(z, 1.5)), we then have diff(dL(x), x) = diff(dz(x), x).  Consequently, we have 

 

E(r) 

 

 

 

 

 

 


 

Table 1  Typewritten solution of given electrostatics problem 

 

In the following sections, Maple solutions of this problem are given, one using the VectorCalculus package, and one using the Physics package.  In each case, the integrals giving the electric field are evaluated.  The electric field vectors are graphed, and field lines are calculated and displayed.  Thus, the ability of Maple to enhance a pedagogical experience is amply manifest. 

 

Maple Solutions 

Solution in the VectorCalculus Package 

 

> with(VectorCalculus); -1
with(plots); -1
with(DEtools); -1
BasisFormat(false); -1
 

>
 

Use of the VectorCalculus package has three advantages.  First, you can control the appearance of vectors with the BasisFormat command.  The default setting causes vectors to be displayed as linear combinations of basis vectors.  The setting chosen here causes vectors to be displayed as column vectors.  To make the change, change "true" to  "false" in the BasisFormat command. 

 

Second, the Norm command defaults to the Euclidean norm and all quantities are treated as real.  At top level, the vectors would also appear as columns, but the available vector norm would treat quantities as complex, and complex conjugates and absolute values would then appear. 

 

Third, the int command is modified.  At top level, int represents integration in a single variable, and does not automatically map to the components of a vector.  In VectorCalculus, int can be used to represent iterated (multiple) integrals, and also maps automatically to vectors. 

 

Because Maple understands the prime as a differentiation operator, it's a lot of work to over-ride the prime and use it strictly as notation. Hence, R will be used for diff(r(x), x), and Z for diff(z(x), x).  With these conventions, make the following definitions. 

 

> `:=`(`#mi(`(x, 0, z)); -1" align="center" border="0">
`:=`(R, `<,>`(0, 0, Z)); -1
`:=`(d, `+`(`#mi(
`#mi(
 

Vector[column](%id = 64035452), Vector[column](%id = 65149588), Vector[column](%id = 64839056)
 

>
 

The integrand will then be 

 

> `:=`(f, `/`(`*`(d), `*`(`^`(LinearAlgebra:-Norm(d), 3))))
 

Vector[column](%id = 67578284)
 

>
 

The electric field vector is then 

 

> `:=`(E, `assuming`([int(f, Z = -`/`(3, 2) .. `/`(3, 2))], [positive]))
 

Vector[column](%id = 52127700)
Vector[column](%id = 52127700)
Vector[column](%id = 52127700)
Vector[column](%id = 52127700)
Vector[column](%id = 52127700)
 

>
 

Notice that Maple has evaluated the integral and returned the electric field as a vector. 

 

Setting y = 0 and calling x by the name r gives the cylindrically symmetric solution obtained in Table 1. 

 

> `:=`(EE, eval(E, [x = r, y = 0]))
 

Vector[column](%id = 69107700)
Vector[column](%id = 69107700)
Vector[column](%id = 69107700)
Vector[column](%id = 69107700)
Vector[column](%id = 69107700)
 

>
 

The reader should pay particular attention to a notational issue not obvious without comment.  The name r has been assigned a vector as its value.  Ordinarily, this would persist in the substitution made into E.  To avoid this clash, we have converted r to an "atomic identifier" via Context Menu: 2-D Math≻Convert To≻Atomic Identifier.  The symbol r is now seen by Maple as a name distinct from r. 

 

>
 

Graphics 

 

Figure 1 provides a graph of the electric field as a collection of arrows.  

fieldplot3d(E, x = 0 .. 2, y = 0 .. 2, z = 0 .. 2, axes = box, fieldstrength = fixed)
fieldplot3d(E, x = 0 .. 2, y = 0 .. 2, z = 0 .. 2, axes = box, fieldstrength = fixed)
 

Plot
 

 

Figure 1   The electric field in `*`(`^`(real, 3)) 

 

Figure 2 shows the electric field restricted to the `*`(r, `*`(z))-plane. 

 

fieldplot([EE[1], EE[3]], r = 0 .. 2, z = 0 .. 2, fieldstrength = fixed) 

Plot_2d
 

 

Figure 2   The electric field drawn in the rz-plane 

 

To obtain field lines, solve the differential equations Typesetting:-delayDotProduct(`/`(`*`(d), `*`(dt)), Vector[column](%id = 62999404), true) = EE.  The dependent variables in EE must explicitly be functions of the independent variable t.  Thus, write 

 

> `:=`(EEE, eval(EE, [r = r(t), z = z(t)])); -1
 

>
 

then obtain numeric solutions and a graph with the DEplot command, as shown in Figure 3. 

 

DEplot([diff(r(t), t) = EEE[1], diff(z(t), t) = EEE[3]], [r(t), z(t)], t = 0 .. 2, r(t) = 0 .. 2, z(t) = 0 .. 2, [seq([0, .1, `+`(`*`(.1, `*`(k)))], k = 1 .. 15)], arrows = medium, linecolor = black, ...
DEplot([diff(r(t), t) = EEE[1], diff(z(t), t) = EEE[3]], [r(t), z(t)], t = 0 .. 2, r(t) = 0 .. 2, z(t) = 0 .. 2, [seq([0, .1, `+`(`*`(.1, `*`(k)))], k = 1 .. 15)], arrows = medium, linecolor = black, ...
DEplot([diff(r(t), t) = EEE[1], diff(z(t), t) = EEE[3]], [r(t), z(t)], t = 0 .. 2, r(t) = 0 .. 2, z(t) = 0 .. 2, [seq([0, .1, `+`(`*`(.1, `*`(k)))], k = 1 .. 15)], arrows = medium, linecolor = black, ...
 

Plot_2d
 

 

Figure 3   Field plot of the electric field, along with several field lines. 

 

>
 

Solution in the Physics Package 

 

An alternative solution in the Physics package displays the unit basis vectors as {`#mover(mi(, and vectors that are linear combinations of these vectors as symbols with an arrow superimposed. 

 

> restart
 

> with(Physics:-Vectors); -1
Setup(mathematicalnotation = true); -1
 

>
 

Define the position vector as `#mover(mi( and the vector diff(r(x), x) as `#mover(mi( by typing 

 

> r_ := x*_i + z*_k;
R_ := Z*_k;
 

>
 

and converting this text input to 2-D Math Input via the Format≻Convert To menu options.  The result will be 

 

> `:=`(`#mover(mi(
`:=`(`#mover(mi(
`:=`(`#mover(mi(
 

 

 

Typesetting:-mprintslash([`:=`(r_, `+`(`*`(x, `*`(_i)), `*`(z, `*`(_k))))], [`+`(`*`(x, `*`(_i)), `*`(z, `*`(_k)))])
Typesetting:-mprintslash([`:=`(R_, `*`(Z, `*`(_k)))], [`*`(Z, `*`(_k))])
Typesetting:-mprintslash([`:=`(d_, `+`(`*`(x, `*`(_i)), `*`(_k, `*`(`+`(z, `-`(Z))))))], [`+`(`*`(x, `*`(_i)), `*`(_k, `*`(`+`(z, `-`(Z)))))])
 

>
 

so that the integrand is 

 

> `:=`(`#mover(mi(
 

Typesetting:-mprintslash([`:=`(f_, `/`(`*`(`+`(`*`(x, `*`(_i)), `*`(_k, `*`(`+`(z, `-`(Z)))))), `*`(`^`(`+`(`*`(`^`(x, 2)), `*`(`^`(`+`(z, `-`(Z)), 2))), `/`(3, 2)))))], [`/`(`*`(`+`(`*`(x, `*`(_i)), ...
 

>
 

The electric field vector is then 

 

> `:=`(`#mover(mi(
 

Typesetting:-mprintslash([`:=`(E_, `/`(`*`(`+`(`*`(2, `*`(`^`(`+`(`*`(4, `*`(`^`(x, 2))), `*`(4, `*`(`^`(z, 2))), `-`(`*`(12, `*`(z))), 9), `/`(1, 2)), `*`(_i, `*`(z)))), `-`(`*`(2, `*`(`^`(`+`(`*`(4,...
Typesetting:-mprintslash([`:=`(E_, `/`(`*`(`+`(`*`(2, `*`(`^`(`+`(`*`(4, `*`(`^`(x, 2))), `*`(4, `*`(`^`(z, 2))), `-`(`*`(12, `*`(z))), 9), `/`(1, 2)), `*`(_i, `*`(z)))), `-`(`*`(2, `*`(`^`(`+`(`*`(4,...
Typesetting:-mprintslash([`:=`(E_, `/`(`*`(`+`(`*`(2, `*`(`^`(`+`(`*`(4, `*`(`^`(x, 2))), `*`(4, `*`(`^`(z, 2))), `-`(`*`(12, `*`(z))), 9), `/`(1, 2)), `*`(_i, `*`(z)))), `-`(`*`(2, `*`(`^`(`+`(`*`(4,...
Typesetting:-mprintslash([`:=`(E_, `/`(`*`(`+`(`*`(2, `*`(`^`(`+`(`*`(4, `*`(`^`(x, 2))), `*`(4, `*`(`^`(z, 2))), `-`(`*`(12, `*`(z))), 9), `/`(1, 2)), `*`(_i, `*`(z)))), `-`(`*`(2, `*`(`^`(`+`(`*`(4,...
 

>
 

The components of the electric field vector can be extracted as 

 

> `:=`(E1, Component(`#mover(mi(
 

Typesetting:-mprintslash([`:=`(E1, `+`(`/`(`*`(2, `*`(z)), `*`(`^`(`+`(`*`(4, `*`(`^`(x, 2))), `*`(4, `*`(`^`(z, 2))), `*`(12, `*`(z)), 9), `/`(1, 2)), `*`(x))), `/`(`*`(3), `*`(`^`(`+`(`*`(4, `*`(`^`...
Typesetting:-mprintslash([`:=`(E1, `+`(`/`(`*`(2, `*`(z)), `*`(`^`(`+`(`*`(4, `*`(`^`(x, 2))), `*`(4, `*`(`^`(z, 2))), `*`(12, `*`(z)), 9), `/`(1, 2)), `*`(x))), `/`(`*`(3), `*`(`^`(`+`(`*`(4, `*`(`^`...
 

>
 

and 

 

> `:=`(E3, Component(`#mover(mi(
 

Typesetting:-mprintslash([`:=`(E3, `+`(`-`(`/`(`*`(2), `*`(`^`(`+`(`*`(4, `*`(`^`(x, 2))), `*`(4, `*`(`^`(z, 2))), `*`(12, `*`(z)), 9), `/`(1, 2))))), `/`(`*`(2), `*`(`^`(`+`(`*`(4, `*`(`^`(x, 2))), `...
 

>
 

 

Legal Notice: ? Maplesoft, a division of Waterloo Maple Inc. 2009. Maplesoft and Maple are trademarks of Waterloo Maple Inc. This application may contain errors and Maplesoft is not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact Maplesoft for permission if you wish to use this application in for-profit activities.