0% found this document useful (0 votes)
51 views

ReportEM Lab2

This document describes a lab report for an electromagnetics course. It includes 3 exercises: 1) Plotting the electric field of a single point charge, 2) Plotting equipotential lines of a single point charge, and 3) Plotting the electric field and equipotential lines of two point charges. For each exercise, the relevant equations are provided and MATLAB code is included to generate the corresponding plots. In exercise 3, the students are asked to vary the charge of one of the points charges and observe the effects on the electric field and equipotential line plots.

Uploaded by

Anh Nguyễn
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

ReportEM Lab2

This document describes a lab report for an electromagnetics course. It includes 3 exercises: 1) Plotting the electric field of a single point charge, 2) Plotting equipotential lines of a single point charge, and 3) Plotting the electric field and equipotential lines of two point charges. For each exercise, the relevant equations are provided and MATLAB code is included to generate the corresponding plots. In exercise 3, the students are asked to vary the charge of one of the points charges and observe the effects on the electric field and equipotential line plots.

Uploaded by

Anh Nguyễn
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

The University of Da Nang

Da Nang University of Technology

EE361 LAB REPORT


APPLIES ELECTROMAGNETICS

Instructor: Thai Vu Hien


Team member: Hoang Thi Hanh Phuc
Nguyen Thi Quynh Anh
EE361 Lab 2
Electrostatics with MATLAB

1. Exercise 1: Plot electric field of a charge


Suppose we have a point charge q 1 = +1C located at the position (q 1 = -0.5 cm, q 1=-0.5
cm). The electric field that this charge generates at a position (x, y) in the charge's plane
is:
q1 q1 ( x−x q 1 ) ∙ ^x + ( y− y q 1 ) ∙ ^y
E 1= R=
3 1
∙ [V/m] (1)
4 π ε0 R 1 4 π ε 0 [ ( x−x q 1 )2 + ( x−x q 1 )2 ]3 /2

Where R1 = ( x−x q 1 ). ^x + ( y − y q 1 ) ∙ ^y is the position vector of the point (x, y) with respect to
the charge.
MATLAB code:
1. clear all;  
2.   
3. % Define the vacuum electric permittivity  
4. eps0 = 8.854e-12;  
5.   
6. % Create a x-y grid [-2cm -> 2cm] x [-2cm -> 2cm]  
7. [x,y] = meshgrid(-2:0.2:2, -2:0.2:2);  
8.   
9. % Define the charge q1  
10.q1 = 1; % charge q1 = +1 Coulomb  
11.% Coordinate of the charge q1: P1(xq1, yq1)  
12.% Note that   
13.% to avoid division by zero  
14.xq1 = -0.5; % xq1 = -0.5 cm  
15.yq1 = -0.5; % yq1 = -0.5 cm  
16.  
17.% Calculate distance from each grid point  
18.% to the point charge q1  
19.R1 = sqrt((x-xq1).^2+(y-yq1).^2);  
20.% Note that: '.^' is elementwise exponential  
21.  
22.% Calculate x-component of the electric field  
23.% Note that: '.*' is elementwise multiplication  
24.%            './' is elementwise division  
25.E1x = 1e+4*q1.*(x-xq1)./(4*pi*eps0.*R1.^3);  
26.% Calculate y-component of the electric field  
27.E1y = 1e+4*q1.*(y-yq1)./(4*pi*eps0.*R1.^3);  
28.  
29.%Plot the E-field  
30.figure  
31.streamslice(x, y, E1x, E1y);  
32.axis([-2 2 -2 2]);  
33.hold on;  
34.xticks([-2 -1 0 1 2]);  
35.xlabel('x [cm]');  
36.yticks([-2 -1 0 1 2]);  
37.ylabel('y [cm]');  
38.hold off;  
39.subtitle('QuynhAnh-HanhPhuc');  
40. colormap('jet');  
The plot:

2. Exercise 2: Plot equipotential lines


The electric potential at the point (x, y) in the electric field of charge q 1 is:
q1 q1
v1 = = [V] (2)
4 π ε0 R 1 4 π ε
0 √( x−x q1
2
) +¿ ¿ ¿
MATLAB code:
1. clear all;  
2.   
3. % Define the vacuum electric permittivity  
4. eps0 = 8.854e-12;  
5.   
6. % Create a x-y grid [-2cm -> 2cm] x [-2cm -> 2cm]  
7. [x,y] = meshgrid(-2:0.2:2, -2:0.2:2);  
8.   
9. % Define the charge q1  
10.q1 = 1; % charge q1 = +1 Coulomb  
11.% Note that the charge should not be on the grid  
12.% to avoid division by zero  
13.xq1 = -0.5; % xq1 = -0.5 cm  
14.yq1 = -0.5; % yq1 = -0.5 cm  
15.  
16.% Calculate distance from each grid point  
17.% to the point charge q1  
18.R1 = sqrt((x-xq1).^2+(y-yq1).^2);  
19.% Note that: '.^' is elementwise exponential  
20.  
21.% Calculate x-component of the electric field  
22.% Note that: '.*' is elementwise multiplication  
23.%            './' is elementwise division  
24.E1x = 1e+4*q1.*(x-xq1)./(4*pi*eps0.*(R1).^3);  
25.% Calculate y-component of the electric field  
26.E1y = 1e+4*q1.*(y-yq1)./(4*pi*eps0.*(R1).^3);  
27.  
28.% Calculate voltage  
29.V1 = 1e+2*q1./(4*pi*eps0.*R1);  
30.  
31.% Plot the E-field  
32.figure  
33.contour(x, y, V1, 21, 'linewidth', 1);  
34.hold on;  
35.streamslice(x, y, E1x, E1y);  
36.axis([-2 2 -2 2]);  
37.hold on;  
38.title('Hanh Phuc - Quynh Anh');  
39.xticks([-2 -1 0 1 2]);  
40.xlabel('x [cm]');  
41.yticks([-2 -1 0 1 2]);  
42.ylabel('y [cm]');  
43.hold off;  
44.colormap('jet');  

The plot:
3. Exercise 3: Electric field and equipotential lines of two charges
3.1 Write your program
In this exercise, you have to write a MATLAB program to plot electric field and
equipotential lines of two charges q 1 = +1C and q 2 = -1C which co-locate in the same
space. The charge q 1 is located at the position P1(-0.5 cm, -0.5 cm), and the charge q 2 is
located at the position P2(0.5 cm, 0.5 cm). Note that the electric field is the
superposition of fields generated by each charge. Refer to previous exercises to write
your program. Briefly describe the electric field and equipotential lines.
MATLAB code:
1. clear all;  
2.   
3. % Define the vacuum electric permittivity  
4. eps0 = 8.854e-12;  
5.   
6. % Create a x-y grid [-2cm -> 2cm] x [-2cm -> 2cm]  
7. [x,y] = meshgrid(-2:0.2:2, -2:0.2:2);  
8.   
9. % Define the charge q1  
10.q1 = 1; % charge q1 = +1 Coulomb  
11.% Coordinate of the charge q1: P1(xq1, yq1)  
12.% Note that   
13.% to avoid division by zero  
14.xq1 = -0.5; % xq1 = -0.5 cm  
15.yq1 = -0.5; % yq1 = -0.5 cm  
16.  
17.% Define the charge q2  
18.q2 = -1; % charge q2 = -1 Coulomb  
19.% Coordinate of the charge q2: P2(xq2, yq2)  
20.% Note that   
21.% to avoid division by zero  
22.xq2 = 0.5;  
23.yq2 = 0.5;  
24.  
25.% Calculate distance from each grid point  
26.% to the point charge q1 & q2  
27.R1 = sqrt((x-xq1).^2+(y-yq1).^2);  
28.R2 = sqrt((x-xq2).^2+(y-yq2).^2);  
29.% Note that: '.^' is elementwise exponential  
30.  
31.% Calculate x-component of the electric field  
32.% Note that: '.*' is elementwise multiplication  
33.%            './' is elementwise division  
34.E1x = 1e+4*q1.*(x-xq1)./(4*pi*eps0.*R1.^3);  
35.E2x = 1e+4*q2.*(x-xq2)./(4*pi*eps0.*R2.^3);  
36.Ex=E1x+E2x;  
37.% Calculate y-component of the electric field  
38.E1y = 1e+4*q1.*(y-yq1)./(4*pi*eps0.*R1.^3);  
39.E2y = 1e+4*q2.*(y-yq2)./(4*pi*eps0.*R2.^3);  
40.Ey=E1y+E2y;  
41.  
42.% Calculate voltage  
43.V1 = 1e+2*q1./(4*pi*eps0.*R1);  
44.V2 = 1e+2*q2./(4*pi*eps0.*R2);  
45.V=V1+V2;  
46.  
47.% Plot the E-field  
48.figure  
49.contour(x, y, V, 21, 'linewidth', 0.4);  
50.hold on;  
51.streamslice(x, y, Ex, Ey);  
52.axis([-2 2 -2 2]);  
53.hold on;  
54.title('Hanh Phuc - Quynh Anh');  
55.xticks([-2 -1 0 1 2]);  
56.xlabel('x [cm]');  
57.yticks([-2 -1 0 1 2]);  
58.ylabel('y [cm]');  
59.hold off;  
60.colormap('jet');  

The plot:

Comment:
 Two charges interact with each other.
 Charges of the same sign repel each other.
 Charges with different signs attract each other.

3.2 Observe the electric field


Now, charge value of the charge q 2 to -2 C, 1 C, 2 C and plot the electric field and
equipotential lines for each case. (Keep value of the charge q 1=1 and positions of all the
charges)
MATLAB code:
1. clear all;  
2.   
3. % Define the vacuum electric permittivity  
4. eps0 = 8.854e-12;  
5.   
6. % Create a x-y grid [-2cm -> 2cm] x [-2cm -> 2cm]  
7. [x,y] = meshgrid(-2:0.2:2, -2:0.2:2);  
8.   
9. % Define the charge q1  
10.q1 = 1; % charge q1 = +1 Coulomb  
11.% Coordinate of the charge q1: P1(xq1, yq1)  
12.% Note that   
13.% to avoid division by zero  
14.xq1 = -0.5; % xq1 = -0.5 cm  
15.yq1 = -0.5; % yq1 = -0.5 cm  
16.  
17.% Define the charge q2  
18.q2 = -2; % charge q2 = -1 Coulomb 
19.% q2= 1;
20.% q2 = 2; 
21.% Coordinate of the charge q2: P2(xq2, yq2)  
22.% Note that   
23.% to avoid division by zero  
24.xq2 = 0.5;  
25.yq2 = 0.5;  
26.  
27.% Calculate distance from each grid point  
28.% to the point charge q1 & q2  
29.R1 = sqrt((x-xq1).^2+(y-yq1).^2);  
30.R2 = sqrt((x-xq2).^2+(y-yq2).^2);  
31.% Note that: '.^' is elementwise exponential  
32.  
33.% Calculate x-component of the electric field  
34.% Note that: '.*' is elementwise multiplication  
35.%            './' is elementwise division  
36.E1x = 1e+4*q1.*(x-xq1)./(4*pi*eps0.*R1.^3);  
37.E2x = 1e+4*q2.*(x-xq2)./(4*pi*eps0.*R2.^3);  
38.Ex=E1x+E2x;  
39.% Calculate y-component of the electric field  
40.E1y = 1e+4*q1.*(y-yq1)./(4*pi*eps0.*R1.^3);  
41.E2y = 1e+4*q2.*(y-yq2)./(4*pi*eps0.*R2.^3);  
42.Ey=E1y+E2y;  
43.  
44.% Calculate voltage  
45.V1 = 1e+2*q1./(4*pi*eps0.*R1);  
46.V2 = 1e+2*q2./(4*pi*eps0.*R2);  
47.V=V1+V2;  
48.  
49.% Plot the E-field  
50.figure  
51.contour(x, y, V, 21, 'linewidth', 0.4);  
52.hold on;  
53.streamslice(x, y, Ex, Ey);  
54.axis([-2 2 -2 2]);  
55.hold on;  
56.title('Hanh Phuc - Quynh Anh');  
57.xticks([-2 -1 0 1 2]);  
58.xlabel('x [cm]');  
59.yticks([-2 -1 0 1 2]);  
60.ylabel('y [cm]');  
61.hold off;  
62.colormap('jet');  

The plot:
 q2 = -2 C

 q2 = 2 C
 q2 = 2 C
Comment:
 Two charges interact with each other.
 Charges of the same sign repel each other.
 Charges with different signs attract each other.
4. Exercise 4: Electric field and equipotential lines of two charges
In this exercise, you have to write a MATLAB program to plot electric field and
equipotential lines of four charges:
q 1 = +1 C at P1(-0.5 cm, -0.5 cm),

q 2 = -1 C at P2(-0.5 cm, +0.5 cm),

q 3 = +1 C at P3(+0.5 cm, +0.5 cm),

q 4 = -1 C at P4 (+0.5 cm, -0.5 cm).

Briefly describe the electric field and equipotential lines.


MATLAB code:
1. clear all;  
2.   
3. % Define the vacuum electric permittivity  
4. eps0 = 8.854e-12;  
5.   
6. % Create a x-y grid [-2cm -> 2cm] x [-2cm -> 2cm]  
7. [x,y] = meshgrid(-2:0.2:2, -2:0.2:2);  
8.   
9. % Define the charge qi  
10. q1 = 1;  
11. q2 = -1;  
12. q3 = 1;  
13. q4 = -1;  
14.   
15. % Note that the charge should not be on the grid  
16. % to avoid division by zero  
17. xq1 = -0.5; % xq1 = -0.5 cm  
18. yq1 = -0.5; % yq1 = -0.5 cm  
19.   
20. xq2 = -0.5; % xq2 = -0.5 cm  
21. yq2 = 0.5; % xq2 = 0.5 cm  
22.   
23. xq3 = 0.5; % xq3 = 0.5 cm  
24. yq3 = 0.5; % xq3 = 0.5 cm  
25.   
26. xq4 = 0.5; % xq4 = 0.5 cm  
27. yq4 = -0.5; % xq4 = -0.5 cm  
28.   
29. % Calculate distance from each grid point  
30. % to the point charge q1 and q2  
31. R1 = sqrt((x-xq1).^2+(y-yq1).^2);  
32. R2 = sqrt((x-xq2).^2+(y-yq2).^2);  
33. R3 = sqrt((x-xq3).^2+(y-yq3).^2);  
34. R4 = sqrt((x-xq4).^2+(y-yq4).^2);  
35.   
36. % Calculate x-component of the electric field  
37. E1x = 1e+4*q1.*(x-xq1)./(4*pi*eps0.*(R1).^3);  
38. E2x = 1e+4*q2.*(x-xq2)./(4*pi*eps0.*(R2).^3);  
39. E3x = 1e+4*q3.*(x-xq3)./(4*pi*eps0.*(R3).^3);  
40. E4x = 1e+4*q4.*(x-xq4)./(4*pi*eps0.*(R4).^3);  
41. Ex = E1x + E2x + E3x + E4x;  
42. % Calculate y-component of the electric field  
43. E1y = 1e+4*q1.*(y-yq1)./(4*pi*eps0.*(R1).^3);  
44. E2y = 1e+4*q2.*(y-yq2)./(4*pi*eps0.*(R2).^3);  
45. E3y = 1e+4*q3.*(y-yq3)./(4*pi*eps0.*(R3).^3);  
46. E4y = 1e+4*q4.*(y-yq4)./(4*pi*eps0.*(R4).^3);  
47. Ey = E1y + E2y + E3y + E4y;  
48.   
49. % Calculate voltage  
50. V1 = 1e+2*q1./(4*pi*eps0.*R1);  
51. V2 = 1e+2*q2./(4*pi*eps0.*R2);  
52. V3 = 1e+2*q3./(4*pi*eps0.*R3);  
53. V4 = 1e+2*q4./(4*pi*eps0.*R4);  
54. V = V1 + V2 + V3 + V4;  
55.   
56. % Plot the E-field  
57. figure  
58. contour(x, y, V, 21, 'linewidth', 0.4);  
59. hold on;  
60. streamslice(x, y, Ex, Ey);  
61. axis([-2 2 -2 2]);  
62. hold on;  
63. xticks([-2 -1 0 1 2]);  
64. xlabel('x [cm]');  
65. yticks([-2 -1 0 1 2]);  
66. ylabel('y [cm]');  
67. hold off;  
68. colormap('jet');  
The plot:

Comment:
 Four charges interact with each other.
 Charges of the same sign repel each other.
 Charges with different signs attract each other.

You might also like