Matlab Manual EMFT
Matlab Manual EMFT
ACKNOWLEDGEMENTS
The author would like to acknowledge the help of his colleague Dr. Natalia Nikolova.
Dr. Nikolova was very supportive as the previous instructor of EE3FI4. The author had a
very useful interaction with her when started to teach EE3FI4.
I would like to thank the Center for Leadership in Learning (CLL) for providing most of
the fund for developing this set of MATLAB electromagnetic experiments. CLL has
been a main sponsor of innovation in learning in McMaster. It has supported and
continues to support many of the initiatives in the Department of Electrical and Computer
Engineering.
I would like also to thank my student Chen He for his contribution to this manual. Mr.
He worked very hard with me for 4 months in preparing the MATLAB experiments. Our
target was to make our electromagnetic courses less abstract and more enjoyable for
future students.
Finally, I would to thank my wife and my two beautiful children Omar and Youssef for
their support during the preparation of this manual.
Dr. Mohamed Bakr
Hamilton, September 2006
Contents
Set 1: Vector Analysis Page 1
Set 2: Surface and Volume Integrals
.. Page 5
Page 14
.. Page 28
Page 40
Page 45
Page 84
Page 89
ECE2FH3 - Electromagnetics I
Page: 1
ECE2FH3
Electromagnetics I
Term II, January April 2012
Example: Given the points M(0.1,-0.2,-0.1), N(-0.2,0.1,0.3) and P(0.4,0,0.1), find: a) the vector R NM , b)
the dot product R NM i R PM , c) the projection of R NM on RPM and d) the angle between RNM and RPM.
Write a MATLAB program to verify your answer.
P (0.4, 0,0.1)
N (0.2, 0.1,0.3)
ECE2FH3 - Electromagnetics I
Page: 2
Analytical Solution:
a) R NM = R MO R NO
= (0.1a x 0.2a y 0.1a z ) (0.2a x + 0.1a y + 0.3a z )
= 0.3a x 0.3a y 0.4a z
b) R PM = R MO R PO
= (0.1a x 0.2a y 0.1a z ) (0.4a x + 0.1a z )
= 0.3a x 0.2a y 0.2a z
R NM iR PM = (0.3a x 0.3a y 0.4a z )i(0.3a x 0.2a y 0.2a z )
= 0.3 (0.3) + (0.3) (0.2) + (0.4) (0.2)
= 0.09 + 0.06 + 0.08 = 0.05
R iR
c) projR PM R NM = NM PM R PM
R PM iR PM
0.05
=
(0.3a x 0.2a y 0.2a z )
2
(0.3) + (0.2) 2 + (0.2) 2
= 0.088a x 0.059a y 0.059a z
d) cos =
=
R NM iR PM
| R NM | |R PM |
Definition
Let u=(u 1 ,,u n )
and v=(v 1 ,,v n )
be two vectors in R n . The dot
product of u and v is defined
by
u i v=u 1 v 1 + +u n v n
The dot product assigns a real
number to each pair of vectors.
0.05
(0.3) + (0.3) + (0.4) 2 (0.3) 2 + (0.2) 2 + (0.2) 2
2
= 0.208
Definition
Let u and v be two nonzero vectors in R n . The cosine of the
uv iv
, 0
angle between these vectors is cos =
|u|i|v|
u
Definition
The projection of a vector v
onto a nonzero vector u in R n
is denoted proj u v and is defined
by
v iu
u
proj u v =
ui u
v
proju v
ECE2FH3 - Electromagnetics I
Page: 3
R_PM_dot_R_NM=dot(R_PM,R_NM);%the dot
product of R_PM and R_NM
R_PM_dot_R_PM=dot(R_PM,R_PM);%the dot product of R_PM and R_PM
R_NM =
0.3000 -0.3000 -0.4000
R_PM_dot_R_NM =
0.0500
Proj_R_NM_ON_R_PM =
-0.0882 -0.0588 -0.0588
theta =
1.3613
>>
ECE2FH3 - Electromagnetics I
Page: 4
ECE2FH3 - Electromagnetics I
Page: 5
ECE2FH3
Electromagnetics I
Term II, January April 2012
ECE2FH3 - Electromagnetics I
Page: 6
Analytical Solution:
The closed surface in this problem is shown in Figure
2.1 and Figure 2.2. To find the volume v of a closed
surface we first find out dv, the volume element. In
cylindrical
coordinates,
dv
is
given
by
dv = d d dz as shown in Figure 2.2. Once we get
the expression of dv, we integrate dv over the entire
volume.
dv
dv = d d dz
v = dv
v
= d d dz
v
=4
=4
=2
=2
= 60
= 20
z =3
d d dz
60
180
20
=
180
1
= 2
2
z =5
=4
=2
dv
d
18
2
=
18
z =5
z =3
dz
z =5
z z =3
1
6
2
= (42 22 ) ( ) (5 3)
2
18
18
8
= = 8.378
3
dz
ECE2FH3 - Electromagnetics I
Page: 7
S3
S1
S6
S5
S2
d S2 = d dz = 4 =4 d dz
The steps to evaluate the area of each surface are
executed as follows:
dS1 = d dz
S4
S1 = dS1
s
= d dz
s
60
180
20
=
180
= 2
= 2
18
2
=
18
z =5
z =3
dz
z =5
z z =3
S1
6
2
= 2 ( ) (5 3)
18
18
8
= m2
9
S 2 = dS2
S
= d dz
S
60
180
20
=
180
= 4
= 4
18
2
=
18
dS1
z =5
z =3
dz
z =5
z z =3
6
2
= 4 ( ) (5 3)
18
18
16
= m2
9
ECE2FH3 - Electromagnetics I
Page: 8
d S
S3
d d
dS3
=4
=2
18
2
=
18
1
= 2
2
=4
=2
18
2
=
18
1
6
2
)
(4 2 2 2 ) (
2
18
18
4
= m2
3
=
dS5 = d dz
S5 =
d S
dS5
dz
d d z
dS5
S5
=4
=2
=4
=2
z=5
z=3
dz
z=5
z=3
= ( 4 2 ) (5 3)
= 4 m2
S c lo se d = S 1 + S 2 + 2 S 3 + 2 S 5
8
16
4
+
+ 2 + 2
9
9
3
2
= 2 4 .7 5 5 m
=
ECE2FH3 - Electromagnetics I
Page: 9
k =1 j =1 i =1
i , j ,k
= ( i , j , k ) ( ) (z )
k =1 j =1 i =1
j=n
i = n
i = 1 i = 2
k =n
j=
j = 21
k =3
k =2
k =1
ECE2FH3 - Electromagnetics I
Page: 10
MATLAB code:
clc; %clear the command line
clear; %remove all previous variables
V=0;%initialize volume of the closed surface to 0
S1=0;%initialize the area of S1 to 0
S2=0;%initialize the area of S1 to 0
S3=0;%initialize the area of S1 to 0
S4=0;%initialize the area of S1 to 0
S5=0;%initialize the area of S1 to 0
S6=0;%initialize the area of S1 to 0
rho=2;%initialize rho to the its lower boundary
z=3;%initialize z to the its lower boundary
phi=pi/9;%initialize phi to the its lower boundary
Number_of_rho_Steps=100; %initialize the rho discretization
Number_of_phi_Steps=100;%initialize the phi discretization
Number_of_z_Steps=100;%initialize the z discretization
drho=(4-2)/Number_of_rho_Steps;%The rho increment
dphi=(pi/3-pi/9)/Number_of_phi_Steps;%The phi increment
dz=(5-3)/Number_of_z_Steps;%The z increment
%%the following routine calculates the volume of the enclosed surface
for k=1:Number_of_z_Steps
for j=1:Number_of_rho_Steps
for i=1:Number_of_phi_Steps
V=V+rho*dphi*drho*dz;%add contribution to the volume
end
rho=rho+drho;%p increases each time when z has been traveled from its lower boundary to its upper
boundary
end
rho=2;%reset rho to its lower boundary
end
ECE2FH3 - Electromagnetics I
Page: 11
ECE2FH3 - Electromagnetics I
Page: 12
By comparing, we see that the result of our analytical solution is close to the result of our MATLAB
solution.
ECE2FH3 - Electromagnetics I
Page: 13
ECE2FH3 - Electromagnetics I
Page: 14
ECE2FH3
Electromagnetics I
Term II, January April 2012
i P (2, 3, 4)
Q1 = 8.0 nC
L = 2.0 nC/m
Q2 = 8.0 nC
ECE2FH3 - Electromagnetics I
Page: 15
Analytical Solution:
Based on the principle of superposition, the electric field at
P ( 2, 3, 4) is E = E1 + E 2 + E L where E1 and E2 are the
electric fields generated by the point charges 1 and 2,
respectively, and E L is the electric field generated by the
line charge. The electrical field generated by a point charge
is given by
Q
Epoint =
R
4 0 | R |3
where R is the vector pointing from the point charge to the
observation point as shown in Figure 3.2 (a).
Q
R
(a)
a
a1
A'
E A1
Q1
R1
4 0 | R 1 |3
8 109
1
4
109 22 + 32 + 32
36
= 1.395a x + 2.093a y + 2.093a z
E A'1
A
Q2
R2
4 0 | R 2 |3
(b)
a
dL
8 109
1
109 22 + 32 + 52
36
= 0.615a x + 0.922a y + 1.537a z
4
E A (E A' )
E A'
R 2 = (2a x + 3a y + 4a z ) (a z ) = 2a x + 3a y + 5a z
EA
(2a x + 3a y + 3a z )
a1
(2a x + 3a y + 5a z )
3
L
L=0
dE L
dE L1
Figure 3.2.
components
dE L
(c)
The different
field
ECE2FH3 - Electromagnetics I
Page: 16
As we can see from Figure 3.2(b), for any point A on the line charge we can always find one and only one
point A' whose electric field at P has the same magnitude but the opposite sign of that of A in the
direction which is parallel to the line charge. This is because the linear charge is infinitely long. Therefore
we only need to find the electric field in the direction perpendicular to the line charge. As shown in
Figure 3.2(c) each incremental length of line charge dL acts as a point charge and produces an
incremental contribution to the total electric field intensity. The magnitude of dEL is thus:
L dL
dQ
dEL =
=
2
4 0 | R |
4 0 ( L2 + d 2 )
therefore the magnitude of dE is
dEL = dEL sin =
and EL =
L =
L =
EL
L dL
4 0 ( L + d ) ( L + d )
2
Ld
4 0
dE =
Ld
1
=
4 0 2
d2
d 1 + 2
L
dL
Ld
2
4 0 ( L + d 2 )3/ 2
L =
dL
(this integral is given in the formula sheet)
L = ( L + d 2 )3/ 2
d
L
= L
2
4 0 d L2 + d 2
L =
L =
d2
L =
L
1
1
1
= Ld
.
2
=
2
4 0 d 1 + 0 d 1 + 0 2 0 d
d2
1+ 2
L L =
R = (2a x + 3a y + 4a z ) (2a x ) = 3a y + 4a z
a =
R
| R |
3a y + 4a z
3
4
= a y + az
5
5
3 +4
2
therefore
E L = E L = EL a
2 109
4
3
a y + az
1
5
2
109 5 5
36
= 4.32a y + 5.76a z
and
E = E1 + E2 + EL = 2.01a x + 7.34a y + 9.39a z V/m
ECE2FH3 - Electromagnetics I
Page: 17
i
3
3
i =1
i =1 4 0 | R i |
i =1 4 0 | R i |
where Ei is the electric field generated by the ith segment, R i is the vector from the ith segment to the
observation point, Q is the charge of a single segment, L is the length of the segment and n is the total
number of the segments.
i =1
i=2
i
i
i
i d
i
i
i = n 1
Ri
P (2, 3, 4)
i=n
ECE2FH3 - Electromagnetics I
Page: 18
ECE2FH3 - Electromagnetics I
Page: 19
Running result
Comparing the MATLAB answer with the analytical answer we see that there is very little difference
between them. This little difference is caused by the finite length of the steps of L and the finite line
charge that we used to replace the infinite one.
ECE2FH3 - Electromagnetics I
Page: 20
(7, 0, 0)
L = 4nC/m
Q1 = 8 nC
(0, 7, 0)
ECE2FH3 - Electromagnetics I
Page: 21
ECE2FH3
Electromagnetics I
Term II, January April 2012
P(0, 0, 4)
y=
=5
C
/m 2
x=
2
x=
y=
ECE2FH3 - Electromagnetics I
Page: 22
cos =
EA'
EA
EA'1
EA1
z
| Rz |
4
=
=
2
|R|
( x 0) + ( y 0) 2 + (4 0) 2
dxdz
dEz = S
4 | R |2
EAz (EA'z )
4
x + y 2 + 16
2
A'
x + y + 16
2
S
x + z + 16
2
4
2
dxdy
Figure 4.2 The field components.
Ez = dEz
s
=
=
y =3
y =3 x =2
= S
let
y =3
x=2
y =3
x=2
y =3 x =2
y =3 x =2
x=2
x + y + 16
2
(
(
x 2 + y 2 + 16
1
x2 + a2
y =3
a2 a2 + x2
4
y =3
y =3
dxdy
dE z
dE
y =3
(y
dxdy
3
dxdy
3
(let a 2 = y 2 + 16)
dE1
x=2
dy
x =2
+ 16 ) y + 20
2
dy
y = 20 tan
then dy = 20 sec 2 d ,
y 2 + 20 = 20 sec ,
and y 2 + 16 = 20 tan 2 + 16
ECE2FH3 - Electromagnetics I
Page: 23
therefore
Ez =
4S
4S
= 2
20 sec2 d
20 sec
) ( 20 tan + 16 )
2
sec d
2
1 20 tan + 16
1
d
4 S = 2 cos
=
sin 2
=1
+ 16
20
cos 2
4 = 2
cos d
= S
20sin 2 + 16 cos 2
S y =3 cos d
4 = 2 cos d
= S
=
=1 4sin 2 + 16 y =3 sin 2 + 4
let u = sin then du = cos d therefore
=
S u =u du
u =u u 2 + 4
1
u
= S arctan
2
2
Ey =
= 2
y =3
.
y =3
1
u
E y = S arctan
2 =3/
2
29
3
5 10
1
=
2 arctan 29 = 4.8898 104
1
2
109 2
36
E = E y a y = 4.8898 104 a y V/m
6
y 2 + 20
20
y
y + 20
2
ECE2FH3 - Electromagnetics I
Page: 24
MATLAB Solution:
To write a MATLAB code to solve this problem, we equally divide the surface into many cells each with a
length y and a width x . Each cell has a charge of Q = s xy . When x and y are very small, the
electric field generated by this cell is very close to that generated by a point charge with a charge Q
located at the center of the cell. Hence the electric field generated by the surface charge at point P is given
by
m n
m n
xy
E E j ,i = s
R j ,i
3
j =1 i =1
j =1 i =1 4 | R j ,i |
where R j ,i is the vector pointing from the center of a cell to the observation point, as shown in Figure 4.5.
The location of the center of a cell is given by x = 2 +
y
x
+ x(i 1) , y = 3 +
+ y ( j 1) and z = 0.
2
2
E j ,i
P R j ,i
z
j=
j=
i j
=m
i=
i i
i
i
i i
i
y
i i
i =1
ECE2FH3 - Electromagnetics I
Page: 25
ECE2FH3 - Electromagnetics I
Page: 26
Running result:
Comparing the MATLAB answer and the analytical answer we see that there is a slight difference. This
difference is a result of the finite discretization of the surface S.
ECE2FH3 - Electromagnetics I
Page: 27
P( = 0, z = 1)
= 1.0
ECE2FH3 - Electromagnetics I
Page: 28
ECE2FH3
Electromagnetics I
Term II, January April 2012
Q = 1.0 C
Q
R , where R is the vector
4 | R |3
MATLAB Solution:
We first introduce two MATLAB functions that can help us to create a field vector plot.
1 meshgrid
Syntax:
[X,Y] = meshgrid(x,y)
[X,Y,Z] = meshgrid(x,y,z)
ECE2FH3 - Electromagnetics I
Page: 29
1 0 1 2
0 0 0 0
X = 1 0 1 2 , Y = 1 1 1 1
1 0 1 2
2 2 2 2
1 0 1 2
3 3 3 3
If we compare the matrices X and Y with the mesh grids we see that matrix X stores the x components
of all the points in the mesh grids and Y stores the y components of those points. [X,Y,Z] = meshgrid(x,
y,z)is the 3-dementional version of mesh grids. [X,Y,Z] = meshgrid(0:1:4,0: 1:4,0:1:2) creates the
mesh grids shown in Figure 5.4, and matrix X , Y and Z is given by
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
X(:,:,1) = 0 1 2 3 4 X(:,:,2) = 0 1 2 3 4 X(:,:,3) = 0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Y(:,:,1) = 2 2 2 2 2 Y(:,:,2) = 2 2 2 2 2 Y(:,:,3) = 2 2 2 2 2
3 3 3 3 3
3 3 3 3 3
3 3 3 3 3
4 4 4 4 4
4 4 4 4 4
4 4 4 4 4
2 2 2 2 2
1 1 1 1 1
0 0 0 0 0
2 2 2 2 2
1 1 1 1 1
0 0 0 0 0
Z(:,:,3) = 2 2 2 2 2
Z(:,:,1) = 0 0 0 0 0 Z(:,:,2) = 1 1 1 1 1
2 2 2 2 2
1 1 1 1 1
0 0 0 0 0
2 2 2 2 2
1 1 1 1 1
0 0 0 0 0
Similar to the two-dimensional version, the matrices X, Y and Z store the x, y, and z components of all the
plotting points, respectively.
2 quiver/quiver3
Syntax:
quiver(X,Y,x_data,y_data)
quiver3(X,Y,Z,x_data,y_data,z_data)
ECE2FH3 - Electromagnetics I
Page: 30
1
x
ECE2FH3 - Electromagnetics I
Page: 31
1
2
3
4
0
y
ECE2FH3 - Electromagnetics I
Page: 32
Running result:
Figure 5.5 Plot of the electric flux resulting from a point charge located at the origin.
ECE2FH3 - Electromagnetics I
Page: 33
y
5
L = 1 C/m
1
5
L = 1 C/m
Figure 5.6 line charges with charge density of L = 1.0 C/m located at y=1.0 and y=-1.0 on the x-y
plane.
ECE2FH3 - Electromagnetics I
Page: 34
ECE2FH3
Electromagnetics I
Term II, January April 2012
Q =1 C
Figure 6.1 The point charge of Q = 1.0 C and the infinite x-y plane.
ECE2FH3 - Electromagnetics I
Page: 35
where ds is a vector whose direction is normal to the surface element ds and has a magnitude of ds,
and DS is the electric flux density passing through ds. In this problem (See Figure 6.2)
Q
DS =
aR
4 R 2
ds = ds (a z ) = dxdya z
therefore the flux is given by
Q
= DS ids =
a i dxdya z ) .
2 R (
4 R
S
S
This is the general method to evaluate the electric flux passing through a surface. However, for certain
problems we can create a Gaussian surface to find out the flux passing through the surface and avoid
evaluating any integral. The Gaussian surface we created for this problem is shown in Figure 6.3, where
Stop and Sbottom are two parallel planes symmetric relative to the point charge Q. Based on Gausss law,
the total flux passing through the enclosed surface is
total = top + bottom + side1 + side2 + side3 + side4 = charge enclosed = Q
since Stop and Sbottom are symmetric relative to the point charge Q ,
top = bottom .
Using the same reason
side1 = side2 = side3 = side4
and since
side1 <
Q
Qd
(2 Ld ) =
2
4 L
2 L
Qd
0 as L
2 L
we have
side1 0 as L
Hence as L
total = top + bottom =2 bottom = Q
bottom =
Q
= 0.5 C
2
ECE2FH3 - Electromagnetics I
Page: 36
Q = 2 C
dS
DS
Figure 6.2 The electric flux through a surface element resulting from a point charge.
S side
Ss
ide
4
St
op
L'
A'
Ss
ide
1
Sb
otto
m
S side
Figure 6.3 The electric field intensity at a point A is greater than any other point A ' on the plane
S side1 since L < L ' . It follows that the flux through S side1 , side1 , is smaller than (Area of S side1 )
( |electric field density at point A|).
ECE2FH3 - Electromagnetics I
Page: 37
MATLAB Solution:
To write a MATLAB program, we replace the infinite plane with a finite one with a very large area. We
equally divide this plane into a number of surface elements each has an area of S . We then evaluate the
flux passing through each cell and add all the together. This approach can be summarized by:
m n
m n
=
D
i
S
a
i( Si , j a z )
,
i, j
i, j
Ri
j
2
i, j
j =1 i =1
j =1 i =1
j =1 i =1 4 Ri , j
where R i , j is the vector pointing from the point charge to the center of the cell with indices i and j. Note that
ECE2FH3 - Electromagnetics I
Page: 38
Comparing the MATLAB answer and the analytical answer we see that there is a good agreement
between them. The small difference between the two answers is attributed to the finite discretizations of
the surface S, and to utilizing a finite plane instead of the actual infinite plane.
ECE2FH3 - Electromagnetics I
Page: 39
(0, 1, 1)
(0, 0, 1)
(0, 1, 1)
x=
x=
Figure 6.4 a linear charge extending from (0, 1, 1) to (0, 1, 1) and a plane with infinite length
and finite width.
ECE2FH3 - Electromagnetics I
Page: 40
ECE2FH3
Electromagnetics I
Term II, January April 2012
B (0, 0, 2.0) m
A(0, 0,1.0) m
= 1.0 m
L = 2.0 nC/m
Figure 7.1 A ring linear charge with charge density of L = 2.0 nC/m on the x-y plane.
ECE2FH3 - Electromagnetics I
Page: 41
Analytical Solution:
The potential difference between points A and B is given by
z
VAB = E dL
B
dE
dE z
VAB = E dL =
z =1.0
z = 2.0
E a z dz =
z =1.0
z = 2.0
Ez =
L zd
4 0 ( z 2 +
z
=0
Ez =
L z
4 0 ( z 2 +
VAB =
z =1.0
z = 2.0
L zd
4 0 ( z 2 + 2 )
= 2
=0 =
Ez dz =
z = 2.0
3/ 2
L z
2 0 ( z 2 + 2 )
L z
z =1.0
2 0 ( z 2 + 2 )
3/ 2
3/ 2
dz
L u =u 1
du
4 0 u =u u 3/ 2
1
u = u1
= L ( 2u 1/ 2 )
4 0
u = u2
= L
2 0
1
z2 + 2
z =1.0
z = 2.0
2.0 10 1.0
1
1
2
2
1
2.02 + 1.02
109 1.0 + 1.0
2
36
= 29.4 V
dl
y
2 3/ 2
2 3/ 2
= 2
dE =
Ez dz .
dE
ECE2FH3 - Electromagnetics I
Page: 42
VAB = V j
j =1
m
= E j L j
j =1
m n
L l
n
= E j , i ( L j ) =
R
L j )
j
i
,
2
(
j =1 i =1
j =1 i =1 4 0 | R j ,i |
B
j =1
j=2
i R j ,i
i
j=n
A
i=n
i=5
i=4
i=3
i=2
i =1
Figure 7.3 The ring charge is divided along the a direction and the integral path is divided along
the a z direction.
ECE2FH3 - Electromagnetics I
Page: 43
Running result
>> V
V=
29.3931
>>
Comparing both answers, we see that our MATLAB solution and the analytical solution are consistent.
ECE2FH3 - Electromagnetics I
Page: 44
i A (3.0, 4.0,12.0)
V =
1
C/m3
2
r
1
C/m 3 in the region bounded by 1.0 m < r < 1.5 m .
2
r
ECE2FH3 - Electromagnetics I
Page: 45
ECE2FH3
Electromagnetics I
Term II, January April 2012
5 104
electric energy stored in the region bounded by1.0 m < < 2.0 m , 2.0 m < z < 2.0 m and 0 < < 2 , as
shown in Figure 8.1.Verify your answer using a MATLAB program.
z
2 = 2.0 m
1 = 1.0 m
Figure 8.1 The region bounded by 1.0 m < < 2.0 m , 2.0 m < z < 2.0 m and 0 < < 2 .
ECE2FH3 - Electromagnetics I
Page: 46
2.5 109 0
2
z = 2.0
= 2
z =2.0 = 0
= 2.0
=1.0
d d dz
z
=
=
2.0
0
2
z = 2.0
2.5 109 0
2
=
ln(2)
0 dz
z =2.0
2
9
2.5 10 0
z = 2.0
=
ln(2) 2 z z =2.0
2
1
2.5 109
109
36
=
ln(2) 2 4 = 0.19254 J
2
=
MATLAB Solution:
To write a MATLAB program to evaluate the energy stored in the given region, we can divide the region
into many small volume elements and evaluate the energy in each of these elements. Finally, the
summation of these energies will be close to the total energy stored in the given region. The approach can
be summarized using the mathematical expression:
p
WE = WE k , j ,i
k =1 j =1 i =1
p m n
1
= 0 | Ek , j ,i |2 vk , j ,i
k =1 j =1 i =1 2
2
1 5 104
z
= 0
k , j ,i k , j ,i
k =1 j =1 i =1 2
ECE2FH3 - Electromagnetics I
Page: 47
MATLAB code:
clc; %clear the command line
clear; %remove all previous variables
Epsilono=1e-9/(36*pi); %use permitivity of free space
rho_upper=2.0;%upper bound of rho
rho_lower=1.0;%lower bound of rho
phi_upper=2*pi;%upper bound of phi
phi_lower=0;%lower bound of phi
z_upper=2;%upper bound of z
z_lower=-2;%lower bound of z
Number_of_rho_Steps=50; %initialize discretization in the rho direction
drho=(rho_upper-rho_lower)/Number_of_rho_Steps; %The rho increment
Number_of_z_Steps=50; %initialize the discretization in the z direction
dz=(z_upper-z_lower)/Number_of_z_Steps; %The z increment
Number_of_phi_Steps=50; %initialize the phi discretization
dphi=(phi_upper-phi_lower)/Number_of_phi_Steps; %The step in the phi direction
WE=0;%the total engery stored in the region
for k=1:Number_of_phi_Steps
for j=1:Number_of_z_Steps
for i=1:Number_of_rho_Steps
rho=rho_lower+0.5*drho+(i-1)*drho; %radius of current volume element
z=z_lower+0.5*dz+(j-1)*dz; %z of current volume element
phi=phi_lower+0.5*dphi+(k-1)*dphi; %phi of current volume element
EMag=5e4/rho;%magnitude of electric field of current volume element
dV=rho*drho*dphi*dz;%volume of current element
dWE=0.5*Epsilono*EMag*EMag*dV;%energy stored in current element
WE=WE+dWE;%get contribution to the total energy
end %end of the i loop
end %end of the j loop
end %end of the k loop
Running result:
>> WE
WE =
0.1925
>>
Comparing the two answers, we see that our MATLAB solution and analytical solution are consistent.
ECE2FH3 - Electromagnetics I
Page: 48
S = 2.0 C/m 2
r = 1.0 m
ECE2FH3 - Electromagnetics I
Page: 49
ECE2FH3
Electromagnetics I
Term II, January April 2012
Figure 9.1 Surface bounded by r = 0.8 , 0.1 < < 0.3 and 0 < < 2 .
ECE2FH3 - Electromagnetics I
Page: 50
S
=
= 2
=0
= 0.3
= 0.1
400r 2 sin 2
d d
r2 + 4
400r =0.3 = 2 2
sin d d
r 2 + 4 =0.1 =0
= 2
400r 2 =0.3
2
= 2
d
sin
(
)
=0
r + 4 =0.1
2
= 0.3
400r
= 2
2
sin 2 d
0.1
r +4
= 0.3 1
400r 2
cos(2 )
d
= 2
2
0.1
r +4
2
2
let u = 2 then du = 2d and we have
=
I=
u = 0.6 1
400r 2
1 cos u
du
2
2
u = 0.2 2
r +4
2
2
u = 0.6
400r 2
sin u
1
u
= 2
r +4
2 u =0.2
2
=
400 0.82
sin 0.6
1
0.6
2
0.8 + 4
2
2
sin 0.2
1
0.2
2
2
= 77.42 A
MATLAB Solution:
To write a MATLAB program to evaluate the current flowing through the given surface, we divide that
surface into many small surfaces and evaluate the currents flowing through each surface element. The
summation of these elemental currents will be close to the actual current flowing through the given
surface. This approach can be summarized by the following expression:
m
I = J i , j Si , j
j =1 i =1
m n
400sin i , j 2
=
a r ( r sin i , j d i , j d a r )
r2 + 4
j =1 i =1
ECE2FH3 - Electromagnetics I
Page: 51
MATLAB code:
clc; %clear the command line
clear; %remove all previous variables
R=0.8;%the radius of the surface
Theta_lower=0.1*pi;%lower boundary of theta
Theta_upper=0.3*pi;%upper boundary of theta
Phi_lower=0;%lower boundary of phi
Phi_upper=2*pi;%upper boundary of phi
Number_of_Theta_Steps=20; %initialize the discretization in the Theta direction
dTheta=(Theta_upper-Theta_lower)/Number_of_Theta_Steps; %The Theta increment
Number_of_Phi_Steps=20;%initialize the discretization in the Phi direction
dPhi=(Phi_upper-Phi_lower)/Number_of_Phi_Steps;%The Phi increment
I=0; %initialize the total current
for j=1:Number_of_Phi_Steps
for i=1:Number_of_Theta_Steps
Theta=Theta_lower+0.5*dTheta+(i-1)*dTheta; %Theta of current surface element
Phi=Phi_lower+0.5*dPhi+(j-1)*dPhi; %Phi of current surface element
x=R*sin(Theta)*cos(Phi); %x coordinate of current surface element
y=R*sin(Theta)*sin(Phi); %y coordinate of current surface element
z=R*cos(Theta); %z coordinate of current surface element
a_r=[sin(Theta)*cos(Phi) sin(Theta)*sin(Phi) cos(Theta)];% the unit vector in the R direction
J=(400*sin(Theta)/(R*R+4))*a_r;%the current density of current surface element
dS=R*R*sin(Theta)*dTheta*dPhi*a_r;%the area of current surface element
I=I+dot(J,dS);%get contribution to the total current
end
end
Running result:
Comparing the answers we see that our MATLAB solution and analytical solution are consistent.
ECE2FH3 - Electromagnetics I
Page: 52
Figure 9.2 The volume between the conducting plates is filled with a material having conductivity
( x ) = e x / 10 S/m.
ECE2FH3 - Electromagnetics I
Page: 53
ECE2FH3
Electromagnetics I
Term II, January April 2012
y
A
y=a
L = 0
y = ah
Figure 10.1 The infinite line charge and the two ground planes.
ECE2FH3 - Electromagnetics I
Page: 54
VMN = E dL =
therefore VMN =
= M
d = L ln
= L ln N
2
2
2 M
=N
L
ln N .
2 M
0
y
y = yA = a
L
ln M .
2
P ' ( xP , 2 y L y P )
yP ' yL = yL yP
yP ' = 2 yL yP
This expression will be used later. To find the coordinates and
polarities of the images, we can divide all the images into two
groups. If we only count the first image of plane B and all the subimages created by that first image, then the images that we counted
are put into group 1 (shown in Figure 10.4). If we only count the
first image of plane A and all the sub-images created by that first
image, then the images that we counted are put into group 2
(shown in Figure 10.5). In group 1, the y coordinate of the first
image is y1 = 2 y A y0 where y A is the y coordinate of plane A
and y0 is the y coordinate of the original charge. Then for the
second image y2 = 2 yB y1 , for the third image y3 = 2 y A y2 and
so on. In group 2, the y coordinate of the first image is
y1 = 2 yB y0 , for the second image y2 = 2 y A y1 , for the third
image y3 = 2 yB y2 and so on. The following table summarizes
the polarities and y coordinates of all images.
y = yB = a h
B
0
y
P '( xP ' , yP ' )
yP ' yL
y = yL
x
yL yP
P( xP , yP )
ECE2FH3 - Electromagnetics I
Page: 55
y coordinate polarity
2a 2h
y2 = 2 y A y1
2h
2a 4h
4h
2a 6h
6h
y coordinate
2a
2h
2a + 2h
4h
2a + 4h
6h
polarity
ln
n =
y = yB = a h
2
2
V=
ln x 2 + ( y 2nh ) +
ln x 2 + ( y 2a 2nh )
n = 2
n = 2
x 2 + ( y 2nh ) + ln x 2 + ( y 2a 2nh )
y1 = 2 yB y0
y1 = 2 y A y0
y
n =
y0 = 0
=
2
y = yA = a
y = yA = a
y0 = 0
y = yB = a h
MATLAB solution:
To plot the contour of the voltage, we can use the expression we
derived to evaluate voltages at all plotting points, then store the
voltages in a two-dimensional matrix.
y2 = 2 yB y1
ECE2FH3 - Electromagnetics I
Page: 56
ECE2FH3 - Electromagnetics I
Page: 57
Running result:
ECE2FH3 - Electromagnetics I
Page: 58
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1
-0.8
-0.6
-0.4
-0.2
0.2
0.4
0.6
0.8
y
y=a
x=a
x = a
y = a
ECE2FH3 - Electromagnetics I
Page: 59
ECE2FH3
Electromagnetics I
Term II, January April 2012
Analytical solution:
The electric field intensity is continuous in the tangential direction of the boundary and the electric flux
density is continuous in the normal direction of the boundary.
2
EN 2
DN 2
E2
D2
EN1
E1
ET 1
ET 2
DN1
D1
DT 2
DT 1
Figure 11.1 The continuity of the electric field intensity and the electric flux density vectors,
ET 1 = ET 2 and D N 1 = D N 2 .
The unit vector that is normal to the surface is
f
aN =
where f = x + y + 2 z , therefore
| f |
a + a y + 2a z
1
=
aN = x
( a x + a y + 2a z )
| a x + a y + 2a z |
6
This normal will point in the direction of increasing f , which will be away from origin, or into region 2.
Then we can find the electric field intensity in region 1. The normal component is given by
1
1
E N 1 = ( E1 a N ) a N = ( 24a x + 36a y + 42a z )
a x + a y + 2a z )
(
( a x + a y + 2a z ) = 24a x + 24a y + 48a z
6
6
ECE2FH3 - Electromagnetics I
Page: 60
Since the electric field intensity is continuous in the tangential direction of the boundary, we have
ET 2 = ET 1 = 12a y - 6a z .
In the normal direction, the electric flux density is continuous, hence
3
D N 1 = D N 2 r1 0 E N 1 = r 2 0 E N 2 E N 2 = r1 E N 1 = ( 24a x + 24a y + 48a z ) = 12a x + 12a y + 24a z
6
r1
Finally, by adding the normal component and the tangential component together, we find the electric field
in region 2,
E2 = ET 2 + E N 2 = (12a y 6a z ) + (12a x + 12a y + 24a z ) = 12a x + 24a y + 18a z V/m.
MATLAB code:
clc; %clear the command line
clear; %remove all previous variables
aN=[1 1 2]/sqrt(6); % unit vector normal to the planar interface
% prompt for input values
disp('Please enter E1, er1 and er2 ')
E1=input('E1=');
er1=input('er1=');
er2=input('er2=');
% perform calculations
E_N1=(dot(E1,aN))*aN; % the normal component of electric field intensity in region 1
E_T1=E1-E_N1;
E_T2=E_T1;
E_N2=E_N1*er1/er2;
E2=E_T2+E_N2;
% display results
disp('The electric field intensity in region 2 is ')
E2
Running result:
ECE2FH3 - Electromagnetics I
Page: 61
r3 = 4
E = a y + az
h3 = 4 104 m
4
r2 = 3
h2 = 3 10
r1 = 2
h1 = 2 104 m
z=0
r0 = 1
ECE2FH3 - Electromagnetics I
Page: 62
ECE2FH3
Electromagnetics I
Term II, January April 2012
+ + + + + + + + + + + + +
x=d
r = 2 + 2 106 x 2
x=0
V =
x=d
x=0
E dL =
x=d
x =0
a x ( a x dx ) =
r 0 S
0S
x=d
x=0
x
Q
1
1
arctan
dx =
6 2
6
6
0S
2 + 2 10 x
10
10 x =0
ECE2FH3 - Electromagnetics I
Page: 63
1
109 0.02
36
= 4.503 1010 C
3
arctan(1000 10 )
2000
2000 0 S
Q
=
=
Q
arctan (1000d ) arctan (1000d )
2000 0 S
MATLAB solution:
We will write a MATLAB program to find the energy stored in the capacitance then use the formula
WE = Q 2 / 2C to evaluate the capacitance. The energy stored in the capacitor is given by
C=
Q
=
V
WE =
1
1
D2
1
D2
2
E
dv
dv
dv
=
=
0
r
2 vol
2 vol r 0
2 vol r 0
Consider a very thin layer of this capacitor. Since the relative dielectric r varies only in the x direction,
we can assume the dielectric is the same everywhere in the very thin layer. Also we note that the electric
flux density is constant along the x direction. Therefore we can write a program that divides the capacitor
into many thin layers and evaluate the energy stored in each layer. We then add all the energy stored in
these layers together to obtain the total energy stored in the capacitor. By knowing the energy stored in the
capacitor, we can calculate the capacitance by using C = Q 2 / 2WE
MATLAB code:
clc; %clear the command line
clear; %remove all previous variables
% initialize variables
eo=1e-9/(36*pi); % the permittivity in free space
Q=4e-9;
S=0.02;
d=1e-3;
Ds=Q/S;
ECE2FH3 - Electromagnetics I
Page: 64
Running result:
Comparing the answers we see that our MATLAB solution and analytical solution are consistent.
Exercise: A very long coaxial capacitor has an inner radius of inner = 1.0 103 m and an outer radius of
inner = 5.0 103 m. It is filled with a nonuniform dielectric characterized by r = 103 . Find the
capacitance of a 0.01 m long capacitor of this kind. Write a MATLAB program that finds the energy
stored in this capacitor if the charge on the inner plate is Q = 5.0 109 C . Use the formula
WE = Q 2 / 2C to evaluate the capacitance again and compare your results.
inner
outer
r = 103
Figure 12.2 The cross section of the coaxial capacitor of the exercise of Set 12.
ECE2FH3 - Electromagnetics I
Page: 65
ECE2FH3
Electromagnetics I
Term II, January April 2012
1.0 m
Gap
Gap
0V
0V
x
O
1.0 m
0V
Figure 13.1 The configuration of the example of Set 13.
ECE2FH3 - Electromagnetics I
Page: 66
V ( x, 0) = 0,
V ( x,1.0) = 1.0
2V 2V
Let V = XY be the solution of
+
= 0, where X is a funtion of x and Y is a function of y. It follows
x 2 y 2
that we have
2V 2V
+
= X '' Y + XY '' = 0
x 2 y 2
X ''
Y ''
=
= 2
X
Y
2
X ''+ X = 0
Y '' 2Y = 0
X = c1 cos x + c2 sin x
Y = c3 cosh y + c4 sinh y
Boundary condition V (0, y ) = 0 indicates V (0, y ) = X (0)Y = 0 , X (0) = c1 cos 0 + c2 sin 0 = 0 c1 = 0
therefore X = c2 sin x (1)
Boundary condition V (1.0, y ) = 0 indicates V (1.0, y ) = X (1.0)Y = 0 , X (1.0) = c2 sin = 0 = n (2)
Boundary condition V ( x, 0) = 0 indicates V ( x, 0) = XY (0) = 0 , Y (0) = c3 cos = 0 c3 = 0 ,therefore
Y = c4 sinh y (3)
With equation (1), (2) and (3), we have
Vn = X nYn = An sin(n x) sinh(n y ) .
The general solution for the Laplace equation is thus given by
V = An sinh(n y ) sin(n x)
n =1
1.0
x =1
2 cos(n x)
2 2 cos(n ) 2 2 (1) n
2 2 (1) n
sin(n x)dx =
=
=
An =
n
n
n
n sinh(n )
x =0
Therefore,
2 2 (1) n
V =
sinh(n y ) sin(n x)
n =1 n sinh( n )
ECE2FH3 - Electromagnetics I
Page: 67
MATLAB code:
NumberOfXPlottingPoints=40; %number of plotting points along the x axis
NumberOfYPlottingPoints=40; %number of plotting points along the y axis
Positive_infinite=160;%use a finite number to replace positive infinite
V=zeros(NumberOfYPlottingPoints,NumberOfXPlottingPoints);% the matrix used to store the voltages at plotting points
PlotXmin=0; %lowest x value on the plot plane
PlotXmax=1; %maximum x value on the plot plane
PlotYmin=0; %lowest y value on the plot plane
PlotYmax=1; %maximum y value on the plot plane
PlotStepX= (PlotXmax-PlotXmin)/(NumberOfXPlottingPoints-1);%plotting step in the x direction
PlotStepY=(PlotYmax-PlotYmin)/(NumberOfYPlottingPoints-1); %plotting step in the y direction
[xmesh,ymesh] = meshgrid(PlotXmin:PlotStepX:PlotXmax,PlotYmin:PlotStepY:PlotYmax);
for j=1:NumberOfYPlottingPoints %repeat for all plot points in the y direction
for i=1:NumberOfXPlottingPoints %repeat for all plot points in the x direction
xplot=PlotXmin+(i-1)*PlotStepX;%x coordinate of current plotting point
yplot=PlotYmin+(j-1)*PlotStepY;%y coordinate of current plotting point
for n=1:Positive_infinite
V(j,i)=V(j,i)+(2-2*(-1)^n)*sinh(n*pi*yplot)*sin(n*pi*xplot)/(n*pi*sinh(n*pi));%get the voltage contribution
end
end
end
surf(xmesh,ymesh,V);%obtain the surface figure
xlabel('x(m)');% label x
ylabel('y(m)');% label y
zlabel('V(V)');% label z
figure;
[C,h] = contour(xmesh,ymesh,V);%obtain the contour figure
set(h,'ShowText','on','TextStep',get(h,'LevelStep'));%label the contour
xlabel('x(m)');% label x
ylabel('y(m)');% label y
figure;
contour(xmesh,ymesh,V); [px,py] = gradient(V);
hold on,quiver(xmesh,ymesh,-px,-py,3),hold off,%obtain the electric field map by using E=-Gradient(V)
xlabel('x(m)');% label x
ylabel('y(m)');% label
ECE2FH3 - Electromagnetics I
MATLAB Examples and Exercises (Set 13)
Running result:
Figure 13.2 The surface of the voltage in the region 0 < x < 1, and 0 < y < 1 .
Figure 13.3 Contours of the voltage in the region 0 < x < 1, and 0 < y < 1 .
Page: 68
ECE2FH3 - Electromagnetics I
MATLAB Examples and Exercises (Set 13)
Figure 13.4 The electric field lines in the region 0 < x < 1, and 0 < y < 1 .
Page: 69
ECE2FH3 - Electromagnetics I
Page: 70
1.0 m
Gap
Gap
0V
1.0 V
Gap
x
O
1.0 m
0V
Figure 13.5 The geometry of the exercise of Set 13.
ECE2FH3 - Electromagnetics I
Page: 71
ECE2FH3
Electromagnetics I
Term II, January April 2012
0.9 mm
V = 1.0 V
0.6 mm
V =0
ECE2FH3 - Electromagnetics I
Page: 72
V1 V0
h
V0 V3
h
V
V
x a x
=
h
y
x
V2
b
V3 c
V1 + V3 2V0
h2
and similarly,
V + V 2V0
2V
= 2 42
2
y 0
h
Substituting in Laplace equation
V1 + V2 + V3 + V4 4V0
2V
2V
+ 2
=0
2
h2
x 0 y 0
or
V +V +V +V
V0 = 1 2 3 4
4
4V0 + V1 + V2 + V3 + V4 = 0 (1)
V1
V4
h
Figure 14.2 A portion of a region containing a twodimensional potential field, divided into square of
side h. The potential V0 is approximately equal to the
average of the potentials at the four neighboring
points.
For points on the inner square of the cable, the voltage is given by
V0 = 1.0 (2)
Then we can obtain a system of linear equations whose unknowns are the voltages of the points inside the
cable. Assume there are n divisions along the x direction and m divisions along the y direction, then we have
total number of m n linear equations, and the system of linear equations is given by
a1,2
a1,3
a1,m( n 2)
a1,m( n 1)
a1,mn V1 b1
a1,1
a2,2
a2,3
a2, m( n 2)
a2,m( n 1)
a2,mn V2 b2
a2,1
a3,1
a3,2
a3,3
a3,m( n 2)
a3, m( n 1)
a3, mn V3 b3
m( n 1)
am( n 1), m( n 2) am( n 1), m( n 1) am( n1),mn Vm( n 1) bm( n 1)
am( n 1),1 am( n 1),2 am( n 1),3
a
amn ,2
amn ,3
amn , m( n 2)
amn , m( n 1)
amn ,mn Vmn bmn
mn ,1
ECE2FH3 - Electromagnetics I
Page: 73
V = Vout
V = Vout
Vi
Vi +1
Vi 1
Vi +1
Vi + n
Vi + n
(a)
Vi
(b)
V = Vi n
Vi = Vinner
Vi 1
Vi
Vi +1
Vi + n
(c)
(d)
Figure 14.3(a) Vi is the voltage on the left corner of the cable; (b) Vi is the voltage on the top of the
cable; (c) Vi is a nodal voltage inside the inner square of the cable; and (d) Vi is the voltage of a
point inside the cable that is not next to the boundary.
ECE2FH3 - Electromagnetics I
MATLAB Examples and Exercises (Set 14)
MATLAB code:
VOut=0;%voltage on outer conductor
VIn=1.0;%voltage on inner conductor
NumberOfXPoints=50; %number of points in the x direction
NumberOfYPoints=NumberOfXPoints; %number of points in the y direction
NumberOfUnKnowns=NumberOfXPoints*NumberOfYPoints; %this is the total number of unknowns
A=zeros(NumberOfUnKnowns, NumberOfUnKnowns); %this is the matrix of coefficients
b=zeros(NumberOfUnKnowns,1);%this is the right hand side vector
jleft=(NumberOfXPoints+1)/3;%index of inner conductor left side
jright=2*jleft;%index of inner conductor right side
ibottom=(NumberOfYPoints+1)/3;%index of inner conductor Bottom side
itop=2*itop;%index of inner conductor Top side
EquationCounter=1; %this is the counter of the equations
for i=1:NumberOfXPoints %repeat for all rows
for j=1:NumberOfYPoints %repeat for all columns
if((i>=ibottom&i<=itop)&(j>=jleft&j<=jright))%V=1 for all points inside the inner conductor
A(EquationCounter, EquationCounter)=1;
b(EquationCounter,1)=VIn;
else
A(EquationCounter, EquationCounter)=-4;
if(j==1) this is the first column
b(EquationCounter, 1)=b(EquationCounter,1)-VOut; % left point is on boundary
else%store the coefficient of the left point
A(EquationCounter,EquationCounter-1)=1.0;
end
if(j==NumberOfYPoints) % this is the last column
b(EquationCounter, 1)= b(EquationCounter,1)-VOut;%on right boundary
else %store coefficient of right boundary
A(EquationCounter, EquationCounter+1)=1.0;
end
if(i==1) % this is the first row
b(EquationCounter,1)=b(EquationCounter,1)-VOut; %top point is on boundary
else %store coefficient of top point
A(EquationCounter, EquationCounter-NumberOfXPoints)=1;
end
if(i==NumberOfXPoints) % this is the last row
b(EquationCounter,1)=b(EquationCounter,1)-VOut; %bottom point is on boundary
else%store coefficient of bottom point
Page: 74
ECE2FH3 - Electromagnetics I
MATLAB Examples and Exercises (Set 14)
A(EquationCounter, EquationCounter+NumberOfXPoints)=1.0;
end
end
EquationCounter=EquationCounter+1;
end
end
V=A\b; %obtain the vector of voltages
V_Square=reshape(V, NumberOfXPoints, NumberOfYPoints);%convert values into a rectangular matrix
surf(V_Square); %obtain the surface figure
figure;
[C,h] = contour(V_Square);% obtain the contour figure
set(h,'ShowText','on','TextStep',get(h,'LevelStep')*2)
colormap cool;
figure;
contour(V_Square);
[px,py] = gradient(V_Square);
hold on, quiver(-px,-py), hold off%obtain the electric field map by using E=-Gradient(V)
Running result:
Page: 75
ECE2FH3 - Electromagnetics I
MATLAB Examples and Exercises (Set 14)
Page: 76
ECE2FH3 - Electromagnetics I
Page: 77
Gap
50 V
Gap
2 cm
4 cm
50 V
2 cm
Gap
100 V
0V
0V
0V
4 cm
ECE2FH3 - Electromagnetics I
Page: 78
ECE2FH3
Electromagnetics I
Term II, January April 2012
P (0, 0, 0.25) . Write a MATLAB program to verify your answer and plot the magnetic field in the x-y
plane in the region 0.5 m x 0.5 m and 0.5 m z 0.5 m .
x-z plane
K = 5.0 a y A/m
y
x
ECE2FH3 - Electromagnetics I
Page: 79
Analytical solution:
As shown in Figure 15.2, since IdL = KdS , the magnetic field resulting from a surface element
IdL R K RdS
, where R is a vector pointing from the surface element to the observation point,
dH P =
=
4 R 3
4 R 3
R = OP OC = 0.25 a z ( x a x + y a y ) = x a x y a y + 0.25 a z .
The cross product of K and R is given by
ax
KR = 0
ay
5
az
5
0
0
0
0
5
0 = ax
+ az
ay
= 1.25a x + 5 xa z , therefore,
y 0.25
x 0.25
x y
x y 0.25
(1.25 a x + 5 x a z ) dxdy , and the magnetic field resulting from the current sheet is
dH P =
4 x 2 + y 2 +
16
H P = dH P =
x = 0.15
3/ 2
y =
1.25 a x + 5 x a z
dxdy
3/ 2
1
2
2
4 x + y +
16
x = 0.15
y =
x = 0.15
y =
1.25 a x
5x a z
dxdy +
dxdy
=
3/
2
3/ 2
x =0.15 y =
x =0.15 y =
1
1
2
4 x + y 2 +
4 x 2 + y 2 +
16
16
We note that the z component is anti-symmetric in x about the origin (odd parity). Since the limits are
symmetric, the integral of the z component over y is zero. We are left with
x =0.15 y =
y =
HP =
x = 0.15
y =
x =0.15 y =
1.25a x
1
4 x 2 + y 2 +
16
dxdy =
3/ 2
x = 0.15
1.25
y
ax
0.15
x
=
4
1
2 1 2
2
x + x + y +
16
16
x = 0.15
1.25
1
=
ax
2
x
=
0.15
4
x2 + 1 x + 1 + 1
16 y 2
16 y 2
x = 0.15
1.25
2
ax
x =0.15 2
1
4
x +
16
dx
y =
dx
2
1
2 1 x
x + 2 +1+
2
16 y
16 y y =
y =
x = 0.15
2.5
2.5
dx =
a x tan 1 ( 4 x )
=
1.0808a x = 0.8601 a x A/m
x =0.15
ECE2FH3 - Electromagnetics I
Page: 80
K = 5.0 a y A/m
C
x
dS
KdS
Figure 15.2 The vector R pointing from the surface element to the observation point. The magnetic
K RdS
field resulting from the surface element is dH P =
.
4 R 3
MATLAB solution:
We can calculate the magnetic field at a point P by calculating the magnetic field resulting from each
surface element and adding all these elementary magnetic fields together. This can be formulated in the
i = n j = m K R S
i, j
mathematical form H P =
. To plot the magnetic field on the x-z plane, we need to build
4 Ri , j 3
i =1 j =1
an array of the plotting plane and calculate H of each plotting point. We use the function quiver to plot
our vector plot.
MATLAB code:
clc; %clear the command window
clear; %clear all variables
d=0.30; %the width of the sheet in the x direction
L=20; %length of sheet in the y direction
J=5; %value of surface current density
Js=J*[0 1 0]; %the vector of surface current density
Xmin=-0.15; %coordinate of lowest x value on sheet
Xmax=0.15; %coordinate of maximum x value on sheet
Ymin=-10; %coordinate of lowest y value on sheet
Ymax=10; %coordinate of maximum y value on sheet
NumberOfXDivisions=20; %number of cells in the x direction
NumberOfYDivisions=100; %number of cells in the y direction
dx=(Xmax-Xmin)/NumberOfXDivisions; %step in the x direction
dy=(Ymax-Ymin)/NumberOfYDivisions; %step in the y direction
ds=dx*dy; %area of one subsection of sheet
ZCellCenter=0; %all points on sheet has a coordinate z=0
NumberOfXPlottingPoints=10; %number of plotting points along the x axis
NumberOfZPlottingPoints=10; %number of plotting points along the z axis
PlotXmin=-0.5; %lowest x value on the plot plane
PlotXmax=0.5; %maximum x value on the plot plane
ECE2FH3 - Electromagnetics I
Page: 81
Bz(m,n)=0;
continue;
end
Rp=[PlotX PlotY PlotZ]; %poistion vector of observation points
for i=1:NumberOfXDivisions %repeat for all divisions in the x direction
for j=1:NumberOfYDivisions %repeat for all cells in the y direction
XCellCenter=Xmin+(i-1)*dx+0.5*dx; %X center of current subsection
YCellCenter=Ymin+(j-1)*dy+0.5*dy; %Y center current subsection
Rc=[XCellCenter YCellCenter ZCellCenter]; %position vector of center of current subsection
R=Rp-Rc; %vector pointing from current subsection to the current observation point
norm_R=norm(R); %get the distance between the current surface element and the observation point
R_Hat=R/norm_R; %unit vector in the direction of R
dH=(ds/(4*pi*norm_R*norm_R))*cross(Js,R_Hat); %this is the contribution from current element
Bx(m,n)=Bx(m,n)+dH(1,1); %increment the x component at the current observation point
Bz(m,n)=Bz(m,n)+dH(1,3); %increment the z component at the current observation point
end %end of j loop
end %end of i loop
end %end of n loop
end % end of m loop
ECE2FH3 - Electromagnetics I
Page: 82
Running result:
ECE2FH3 - Electromagnetics I
Page: 83
I = 2.0 a y A/m
z
y
P
x-y plane
ECE2FH3 - Electromagnetics I
Page: 84
ECE2FH3
Electromagnetics I
Term II, January April 2012
y
I
r = 0.1
z
ECE2FH3 - Electromagnetics I
Page: 85
Analytical Part:
We can assign a unique angle value to each point on the winding. For instance, if a point has a angle of
/ 3 , and it is on the third turn, then the parametric angle value we assign to this point is
' = / 3 + 2 (3 1) = 13 / 3 . In general, ' = + 2(k 1) , where 1 k number of turns and
0 < 2 . Knowing the value of ' , we can find the rectangular coordinate of a point:
x = r cos = r cos + 2 ( k 1) = r cos ' (1)
y = r sin = r sin + 2 ( k 1) = r sin ' (2)
Also, since the z coordinate is linearly increasing along the windings, we have
z z
z ( ) = zmin + max min ( ' 'min ) (3)
( 'max 'min )
Now we want to divide the winding into n segments along the direction of the current I in order to allow
MATLAB program to calculate the magnetic field (see Figure 16.2). We then pick up n+1 points on the
winding. For the ith point, the angle is given by
' 'min
'i = 'min + max
(i 1) .
n
By plugging this equation into (1), (2) and (3), we can find xi , yi , and zi . Also, we can find xi +1 , yi +1 , and zi +1
in the same way. Note the ith segment is a vector given by
Li = ( xi +1 xi )a x + ( yi +1 yi )a y + ( zi +1 zi )a y
and the vector R i (pointing from the center of the ith segment to the observation point) is given by (See
Figure 16.2)
x x y y z z
R i = P Ci = ( x, y, z ) i +1 i , i +1 i , i +1 i
2
2
2
Finally we can calculate the magnetic field at point P using the superposition formula:
n
I Li R i
.
H=
3
i =1 4 | R i |
The problem requires us to plot the magnetic field in the x-z plane. We should thus calculate the magnetic
field at a grid of points on the x-z plane, and store the values in to a two-dimensional matrix.
ECE2FH3 - Electromagnetics I
Page: 86
P ( x, y , z )
Ri
Ci
L i
y
x
Figure 16.2 Li is the ith segment along the winding and R i is the vector pointing from the center
of ith segment to the observation point P.
.
MATLAB code:
clc; %clear the command window
clear; %clear all variables
NumberOfTurns=20; %Number of turns of the solenoid
Radius=0.1; %radius of solenoid
Zmin=-0.5; %coordinate of the lowest point on the solenoid
Zmax=0.5; %coordinate of the highest point on the solenoid
t_min=0; %lowest value of the curve parameter t
t_max=NumberOfTurns*2.0*pi; % for every turn we have an angle increment of 2*pi
NumberOfSegments=100; %we divide the solenoid into this number of segments
t_values=linspace(t_min,t_max, (NumberOfSegments+1))'; %these are the values of the parameter t
x_values=Radius*cos(t_values);
y_values=Radius*sin(t_values);
z_values=Zmin+((Zmax-Zmin)/(t_max-t_min))*(t_values-t_min);
I=3; %value of surface current density
ECE2FH3 - Electromagnetics I
Page: 87
ECE2FH3 - Electromagnetics I
Page: 88
Running result:
Figure 16.3 The magnetic field lines generated by a solenoid centered along the z axis.
ou
t
=2
.5
cm
Exercise: A toroid whose axis is the z axis carries a current of 5.0 A and has 200 turns. The inner radius is
1.5 cm while the outer radius is 2.5 cm. Write a MATLAB program that computes and plots the magnetic
field in the x-y plane in the region 4.0 cm x 4.0 cm and 4.0 cm y 4.0 cm .
I = 5.0 A
Rin =
1.5 c
m
ECE2FH3 - Electromagnetics I
Page: 89
ECE2FH3
Electromagnetics I
Term II, January April 2012
aN
ECE2FH3 - Electromagnetics I
Page: 90
Analytical solution:
As shown in Figure 17.2, if we assume that the filament current is in the +a z direction, the B field of the
filament penetrates the coil in the +a direction and the direction normal to the loop plane is a x . The B
field resulting from a infinite filamentary conductor taking a current I is given by
I
B = 0 a
2
The flux through the coil is now
z =1 y =3 I
z =1 y = 3 Idydz
0
= B dS = 0 a ( a x dydz ) =
( a ) ( a x )
=
=
z = 0 y =1
z
y
0
1
2
2
S
where
a = a x sin + a y cos
therefore
a ( a x ) = sin =
y +1
Now, the flux through the coil is
=
z =1
z =0
y =3
y =1
y =3
y = 3 Iy
0 Iy
I
0
dydz
dy = 0 ln ( y 2 + 1) = (1.6 107 ) I
=
2
2
y
=
1
2
2
4
y =1
1.0
a a x
x
Figure 17.2 is the distance from the straight filament to the observation point, the current is in
the a z direction and by right hand rule the direction normal to the coil is a x .
ECE2FH3 - Electromagnetics I
Page: 91
ECE2FH3 - Electromagnetics I
Page: 92
Running result:
We see that our MATLAB solution has a good agreement with our analytical solution.
Exercise: Two coils with radii a1 and a2 are separated by a distance of d as shown in Figure 17.3. The
dimensions are a1 = 0.01 m, a2 = 0.04 m, and d = 0.1 m. Find the mutual inductance of the coils. Write a
MATLAB program to verify your answer.
a1
d
a2
I2
I1
ECE2FH3 - Electromagnetics I
Page: 93
ECE2FH3
Electromagnetics I
Term II, January April 2012
1
z
dl
ECE2FH3 - Electromagnetics I
Page: 94
B = nI
= nI
( sin )d = nI (cos 2 cos 1 )
3
3
= 1
= 1
2
2
2
R csc
For a sufficiently long solenoid the magnetic field inside the solenoid is approximately the same every
where. We use the magnetic field in the center of the solenoid to evaluate the flux linkage. The magnetic
field at the center of the solenoid is
0.25
0.25
1.9612 NI
B = nI (cos 2 cos 1 ) = nI (
)=
2
2
2
2
h
2
2
2
0.05 + 0.25
0.05 + 0.25
and the flux linkage is
1.9612 N 2 I a 2
= N tot = NBS =
2
h
Finally, we divide by the current to find the inductance
1.9612 N 2 I a 2
L= =
= 1.9357 104 H
I
h
2
MATLAB solution:
The inductance we derived analytically is an approximate value because we are assuming the solenoid is
infinitely long and tightly wrapped. The magnetic field intensity is actually different for different points
inside the solenoid, and the flux linkage to each turn of coil varies. Using a MATLAB program, we can
calculate a more accurate
= 1 + 2 +
+ i +
+ N = i
i =1
i = B m ,n S m ,n ,
n =1 m =1
where S m ,n is the element surface of the cross-sectional area, and B m ,n is the magnetic field intensity at
p
we use p steps in the direction q steps in the direction. We can further simplify the flux linking the
ith loop by:
p
i = q B n S n .
n =1
MATLAB code:
clc; %clear the command window
clear; %clear all variables
mu=4*pi*1e-7;
ECE2FH3 - Electromagnetics I
MATLAB Examples and Exercises (Set 18)
NumberOfTurns=100; %Number of turns of the solenoid
Radius=0.05; %radius of solenoid
Zmin=-0.25; %coordinate of the lowest point on the solenoid
Zmax=0.25; %coordinate of the highest point on the solenoid
t_min=0; %lowest value of the curve parameter t
t_max=NumberOfTurns*2.0*pi; % for every turn we have an angle increment of 2*pi
NumberOfSegments=1000; %we divide the solenoid into this number of segments
t_values=linspace(t_min,t_max, (NumberOfSegments+1))'; %these are the values of the parameter t
x_values=Radius*cos(t_values);%x coordinates of all selected point on the winding
y_values=Radius*sin(t_values);%y coordinates of all selected point on the winding
deltaZ=linspace(Zmin,Zmax,(NumberOfTurns))';%z coodinates increases when turn increases
z_values=zeros(NumberOfSegments,1);
for k=1:NumberOfTurns
z_values((1+(k-1)*10):k*10)=deltaZ(k);
end
I=1; %value of surface current density
aN=[0 0 1];%direction that normal to each turn
NumberOfRhoSteps=20;%the area increasing steps in the rho direction
NumberOfPhiSteps=20;%the area increasing steps in the phi direction
drho=Radius/NumberOfRhoSteps;%area increament along the direction of rho
dphi=2*pi/NumberOfPhiSteps;%area increment along the direction of phi
flux=0;
for m=1:NumberOfTurns
for j=1: NumberOfRhoSteps
rho=(j-1)*drho+0.5*drho; %rho of current surface element
phi=0.5*dphi; %phi of current surface element
dS=rho*drho*dphi;%area of current element
xp=rho*cos(phi);%x coordinate of current surface element
yp=rho*sin(phi);%y coordinate of current surface element
zp=z_values(m,1);%z coordinate of current surface element
Rp=[xp yp zp];%position of current surface element
B=[0 0 0];
for i=1:NumberOfSegments %repeat for all line segments of the solenoid
XStart=x_values(i,1); %x coordinate of the start of the current line segment
XEnd=x_values(i+1,1); %x coordinate of the end of the current line segment
YStart=y_values(i,1); %y coordinate of the start of the current line segment
YEnd=y_values(i+1,1); %y coordinate of the end of the current line segment
Page: 95
ECE2FH3 - Electromagnetics I
Page: 96
Running result:
Comparing the analytical answer and the MATLAB answer we find a significant difference between them.
The actual inductance value should be closer to the MALAB answer. It makes sense that the analytical
answer is larger because we used the strongest magnetic field inside the solenoid (at the center) to
evaluate the flux linkages analytically. If we increase the number of turns of the solenoid and increase the
ratio of h / R , the two answers will have a better agreement.
Exercise: A toroid whose axis is the z axis has 200 turns. The inner radius is 2.0 cm while the outer
radius is 2.5 cm. Find the inductance analytically if the solenoid has 100 turns and r = 1 . Write a
MATLAB program to verify your answer.