ECE 3580: Laboratory #1
Vector Analysis and Electrostatics
Instructor: Elham Salimi (elham.salimi@umanitoba.ca)
TAs: Amirmasoud Amirkabiri (amirkaba@myumanitoba.ca)
Shijie Fu (fus34@myumanitoba.ca)
University of Manitoba — Fall 2024
A: General Instructions
• Prior to your lab session, complete the prelab questions in Section B. Upload your solution to UM Learn. The
submission deadline of the prelab is 2:30 pm on Tuesday of the lab week.
• Review the short MATLAB tutorial at the end of the lab instructions. This will help you become familiar with
some MATLAB visualization and plotting commands. (If you are already familiar with MATLAB, you don’t need
to spend much time on Section C.)
• Attempt all the tasks in section C. The TAs will help you if you have any questions and verify the parts of the
lab that you need to show to the TA.
• A fillable lab answer sheet is available on UM Learn. Enter your answers to the questions for each task on the
answer sheet, and uplaod to UM Learn at the end of each lab.
B: Prelab
Question 1
Given point P (2, 4, −1) and vector A = 2 x̂ − 3 ŷ + ẑ defined in Cartesian coordinates, express vector A at point P
in:
a) cylindrical coordinates.
b) spherical coordinates.
Question 2
Electric field is the negative of the gradient of the electric potential: E = −∇V . Find the electric field E due to the
electric potential V given below defined in Cartesian coordinates:
a) V (x, y) = 10x + 2y 2
[V ]
b) V (x, y) = 2 cos(3x) − 3 sin(2y)
[V ]
1
Question 3
Using the point form of Gauss’s law, find the volume charge density ρv [C/m3 ] corresponding to the electric flux
density D defined in Cartesian coordinates as D(x, y)= 5xx̂ − 2y 2 ŷ [C/m2 ]
H
Hint: Volume charge density is the divergence of the electric flux density: ρv = ∇ · D.
Question 4
Considering the medium to be air, find the curl of electric field in Question 3. Is this result expected? Discuss your
answer.
H
Hint: In electrostatics, the curl of electric field is zero. The electric field (E) and electric flux density (D) are
related by D = εE where ε is the permittivity.
Question 5
Assuming E = x x̂ − y 2 ŷ, evaluate
Z P2
E · dℓ along:
P1
a) Path 1: a straight line from P1 to P2
b) Path 2: a quarter of circle with the radius of 4 from P1 to P2
y
5
P1
4
Path 2
3
2
Path 1
1
0
P2
0
1
2
3
4
5
x
Is the value of this integral on these two paths the same? Can you claim that this line integral is path independent?
Why?
Question 6
Assuming A = y x̂ + x ŷ, evaluate
Z P2
A · dℓ along path 2.
P1
2
H
Hint:
up 2
u2
a2
u
p
−
a − u2 + C
du =
tan−1 √
2
2
a2 − u2
(a2 − u2 )
√
Z p
u a2 − u2
a2
u
2
2
a − u du =
+
sin−1 + C
2
2
a
Z
u
du
p
= sin−1 + C
a
(a2 − u2 )
Z
Question 7
Repeat Question 6 but this time evaluate
Z P2
|A|dℓ along path 2.
P1
Are the values of the integrals in Questions 6 and 7 the same?
H
Hint: p
In this problem, we use dℓ that is dℓ = |dℓ| =
|dℓ| = dr2 + (rdϕ)2 .
p
dx2 + dy 2 . Similarly, in cylindrical coordinates dℓ =
C: Lab Work
Task 1
Using the function cart2sph in MATLAB, express point P in Question 1 of the prelab in spherical coordinates. Plot
the result using scatter3 command. Compare your result with the prelab and explain any differences.
Task 2
Go to the course book website at http://em7e.eecs.umich.edu and use Chapter 3 modules to check your answers
for Question 2 in the prelab. Check if they match with the theory and demonstrate the results to the TAs.
Task 3
For the vector function C(x, y, z) =
z
x
x̂ + ŷ − 2
ẑ, use contour plots in MATLAB to plot |C| on planes:
x2 + z 2
x + z2
a) y = 0, −10 ≤ x ≤ 10, −10 ≤ z ≤ 10
b) y = 10, −10 ≤ x ≤ 10, −10 ≤ z ≤ 10
c) x = 0,
0 ≤ y ≤ 10, −10 ≤ z ≤ 10
Experiment with visualizing this function by using different plotting parameters.
Task 4
√
Find the net force on a test charge Q = 2 [nC] located at (0, 0, −1/ 6) due to charges:
√
a) Q1 = 1 [nC] located at (0, 3/3, 0)
√
b) Q2 = 2 [nC] located at (−3/4, − 3/6, 0)
3
√
c) Q3 = 2 [nC] located at (3/4, − 3/6, 0)
Using MATLAB, find the value of the electric field due to Q1 , Q2 , Q3 at the test charge location.
H
Hint: A sample MATLAB script is provided which plots the force on the test particle. Try to understand it and
modify it to plot the electric field at the location of the test charge.
Task 5
The electric field on the axis of a ring of charge of radius a and a linear charge density of ρℓ is given by
Z π
ρℓ az
ρℓ az
dϕ =
[V /m]
Ez =
2 + z 2 ) 32
2 + z 2 ) 23
2πε
(a
2ε
(a
0
0
0
Plot the magnitude of the electric field vector along the z-axis due to a ring of positive charges in free space. (Note:
the z-axis is the axis of the ring.) Use the following parameters:
ρℓ = 2.5 [nC/m], a = 5 [cm]
Task 6
Write a MATLAB program to determine the line integral of the electric field in Question 5 of the prelab from P1 to
P2 along Path 1. You need to divide the path into N segments. Try different values for N , N ∈ {1, 3, 10, 50}. Check
your results with the theoretical one from the prelab and record them in the answer sheet. Do they converge as N
increases? Show the TAs your program and confirmation of results.
H
Hint: A simple approach to calculate
imation:
R
E.dℓ is to divide the path into segments and use the following approxZ
E.dℓ ≃
N
X
Ei .∆ℓi
i=1
where Ei is the average value of the electric field and ∆ℓi is approximated as a straight line. That is:
Ex (xi+1 ,yi+1 )+Ex (xi ,yi )
, ∆ℓi = xi+1 − xi
yi+1 − yi
Ey (xi+1 ,yi+1 )+Ey (xi ,yi )
2
Ei =
2
y
yi
∆li
yi+1
xi
xi+1
ith Segment
4
x
Task 7 (10% Bonus) You get up to a total of 110% on this lab.
Redo Task 6 for Path 2.
A Short Introduction to MATLAB
At the MATLAB prompt you can use either the help or doc command to find information on any
MATLAB function. Try help * to see the standard operators. For this lab, some of the most basic syntax
and useful function calls you will need are listed below. Perform some of these commands and operations:
• To create a row vector, A:
A = [1 2 3]
• To create a column vector, B:
B = [1; 2; 3]
• Vector operation commands:
C = dot(A,B); %returns the scalar product of the vectors A and B.
• Compare this to (and explain what’s happening in) these expressions:
A*B %this is a matrix multiplication and equivalent to C
B*A %this is also a matrix multiplication, but it is not the same as C (why?)
A.'*B.'
B.'*A.'
• Now try:
C = cross(A,B)
% returns the cross product of the vectors and it doesn't care if they're row or
mcodecolumn vectors.
• Next try:
cross(B,A)
cross(A,A)
cross(B,B)
% result isn't always a row or column
• Now look at the velocity plot commands: quiver and quiver3.
quiver3(x,y,z,u,v,w)%plots vectors with components (u,v,w)at the points (x,y,z).
– The arrays x, y, z, u, v, w must all be the same size and contain the corresponding position
and vector component.
– See help quiver for more detailed information and get accustomed to the different ways of
calling these functions.
• This set of lines plots the vector A as a position vector
O = [0 0 0]
A = [2 3 −1]
quiver3(O(1,1),O(1,2),O(1,3),A(1,1),A(1,2),A(1,3))
Is the length of the vector correct in the plot? How can you make it correct?
documentation on how to use the quiver3 command.)
5
(Check the help