ReportEM Lab3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

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 3
Magnetostatics with MATLAB

1. Exercise 1: Plot magnetic field of a current


Suppose we have a infinitely long current I 1 = +1. ^z[A] flowing in the +z direction. The
current I 1 crosses the z = 0 plane at the position ( x I 1 = −0.5 cm , y I 1=−0.5 cm).
The magnetic field that this current generates at a position (x,y) in the z = 0 plane is
given by:
μ 0 I 1 × R1 μ 0 ^z .[ ( x−x I 1 ) . x^ + ( y − y I 1 ) . ^y ] −μ 0 ( x−x I 1 ) . ^y + μ0 ( y− y I 1 ) . x^
B1= 2
= 2
= 2 [T] (1)
2 Π R1 2 Π R1 2 Π R1

μ0 ( y− y I 1 ) μ0 ( y− y I 1 )
B1 x = = 2 2
2ΠR 2
1
2 Π [ ( x−x I ) + ( y− y I ) ]
1 1

μ 0 ( x−x I 1 ) μ 0 ( x−x I 1)
B1 y = = 2 2
2 Π R21 2 Π [ ( x−x I ) + ( y− y I ) ]
1 1

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 permeability constant  
4. mu0 = 4*pi*1e-7;  
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. I1 = 1;   
10.   
11. xI1 = -0.5; % xI1 = -0.5 cm  
12. yI1 = -0.5; % yI1 = -0.5 cm  
13.   
14. % Calculate distance from each grid point  
15. % to the point charge I1  
16. R1 = sqrt((x-xI1).^2+(y-yI1).^2);  
17.   
18. % Calculate x-component of the magnetic field  
19. B1x = 1e+4*mu0*I1.*(y-yI1)./(2*pi.*(R1).^2);  
20. % Calculate y-component of the magnetic field  
21. B1y = 1e+4*mu0*I1.*-(x-xI1)./(2*pi.*(R1).^2);  
22.   
23. %Plot the B-field  
24. figure  
25. streamslice(x, y, B1x, B1y);  
26. axis([-2 2 -2 2]);  
27. hold on;  
28. title('Hanh Phuc - Quynh Anh');  
29. xticks([-2 -1 0 1 2]);  
30. xlabel('x [cm]');  
31. yticks([-2 -1 0 1 2]);  
32. ylabel('y [cm]');  
33. hold off;  
34. colormap('jet');  
The plot:

Comment:
 The magnetic field lines around a long wire which carries an electric current form
concentric circles around the wire.
 The direction of the magnetic field is perpendicular to the wire
2. Exercise 2: Magnetic field of two current
2.1 Write your program
In this exercise, you have to write a MATLAB program to plot magnetic field and of two
parallel currents I 1 = +1 ⋅ ^z [ A ] and I 2 = −1 ⋅ ^z [ A ] collocating in the same space. The
current I 1 is in the +z direction and the current I 2 is in the -z direction. The two currents
cross the z=0 plane at the position ( x I 1 = −0.5 cm , y I 1=−0.5 cm) and the position ( x I 2 =
+0.5 cm , y I 2=+0.5 cm), respectively. Note that the magnetic field is the superposition of
fields generated by the two currents. Refer to previous exercises to write your program.
Briefly describe the electric field.
MATLAB code:
1. clear all;  
2.   
3. % Define the permeability constant  
4. mu0 = 4*pi*1e-7;  
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. I1 = 1;  
10. I2 = -1;  
11.   
12. xI1 = -0.5; % xI1 = -0.5 cm  
13. yI1 = -0.5; % yI1 = -0.5 cm  
14.   
15. xI2 = 0.5; % xI2 = 0.5 cm  
16. yI2 = 0.5; % yI2 = 0.5 cm  
17.   
18. % Calculate distance from each grid point  
19. % to the point charge I1 and I2  
20. R1 = sqrt((x-xI1).^2+(y-yI1).^2);  
21. R2 = sqrt((x-xI2).^2+(y-yI2).^2);  
22.   
23. % Calculate x-component of the magnetic field  
24. B1x = 1e+4*mu0*I1.*(y-yI1)./(2*pi.*(R1).^2);  
25. B2x = 1e+4*mu0*I2.*(y-yI2)./(2*pi.*(R2).^2);  
26. Bx = B1x + B2x;  
27. % Calculate y-component of the magnetic field  
28. B1y = 1e+4*mu0*I1.*-(x-xI1)./(2*pi.*(R1).^2);  
29. B2y = 1e+4*mu0*I2.*-(x-xI2)./(2*pi.*(R2).^2);  
30. By = B1y + B2y;  
31.   
32. %Plot the B-field  
33. figure  
34. streamslice(x, y, Bx, By);  
35. axis([-2 2 -2 2]);  
36. hold on;  
37. title('Phuc - Anh     [I1 = 1; I2 = 0]');  
38. xticks([-2 -1 0 1 2]);  
39. xlabel('x [cm]');  
40. yticks([-2 -1 0 1 2]);  
41. ylabel('y [cm]');  
42. hold off;  
43. colormap('jet');  
The plot:
Comment:
 The magnetic fields of the two currents are in opposite directions.
 Two magnetic fields of the same magnitude.
2.2 Observe the electric field
Now, change the value of I 2 to, −2 ⋅ ^z [ A ] ,1 ⋅ ^z [ A ] , 2⋅ z^ [ A ] and plot the magnetic field for
each case. (Keep value of I 1 and position of all the currents)
MATLAB code:
1. clear all;  
2.   
3. % Define the permeability constant  
4. mu0 = 4*pi*1e-7;  
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. I1 = 1;  
10. I2 = -2;  
11. %I2 = 1;  
12. %I2 = 2;  
13.   
14. xI1 = -0.5; % xI1 = -0.5 cm  
15. yI1 = -0.5; % yI1 = -0.5 cm  
16.   
17. xI2 = 0.5; % xI2 = 0.5 cm  
18. yI2 = 0.5; % yI2 = 0.5 cm  
19.   
20. % Calculate distance from each grid point  
21. % to the point charge I1 and I2  
22. R1 = sqrt((x-xI1).^2+(y-yI1).^2);  
23. R2 = sqrt((x-xI2).^2+(y-yI2).^2);  
24.   
25. % Calculate x-component of the magnetic field  
26. B1x = 1e+4*mu0*I1.*(y-yI1)./(2*pi.*(R1).^2);  
27. B2x = 1e+4*mu0*I2.*(y-yI2)./(2*pi.*(R2).^2);  
28. Bx = B1x + B2x;  
29. % Calculate y-component of the magnetic field  
30. B1y = 1e+4*mu0*I1.*-(x-xI1)./(2*pi.*(R1).^2);  
31. B2y = 1e+4*mu0*I2.*-(x-xI2)./(2*pi.*(R2).^2);  
32. By = B1y + B2y;  
33.   
34. %Plot the B-field  
35. figure  
36. streamslice(x, y, Bx, By);  
37. axis([-2 2 -2 2]);  
38. hold on;  
39.   
40. if(I2 == -2)  
41.     title('Phuc - Anh     [I1 = 1; I2 = -2]');  
42. elseif(I2 == 1)  
43.     title('Phuc - Anh     [I1 = 1; I2 = 1]');  
44. elseif (I2 == 2)  
45.     title('Phuc - Anh     [I1 = 1; I2 = 2]');  
46. end  
47.   
48. xticks([-2 -1 0 1 2]);  
49. xlabel('x [cm]');  
50. yticks([-2 -1 0 1 2]);  
51. ylabel('y [cm]');  
52. hold off;  
53. colormap('jet');  
The plot:

Comment:
 The magnetic fields of the two currents are in opposite directions.
 Magnetic field 2 is larger than field 1.

Comment:
 The magnetic fields of the two currents are in same directions.
 Two magnetic fields have the same magnitude.
Comment:
 The magnetic fields of the two currents are in opposite directions.
 Magnetic field 2 is larger than field 1.
3. Exercise 3: Magnetic field of four currents
In this exercise, you have to write a MATLAB program to plot magnetic field in the z = 0
plane of four currents:
I 1 = +1 ⋅ ^z [ A ] crossing the z = 0 plane at ( −0.5 cm ,−0.5 cm ),

I 2 = −1 ⋅ ^z [ A ] crossing the z = 0 plane at ( −0.5 cm ,+0.5 cm),

I 3 = +1 ⋅ ^z [ A ] crossing the z = 0 plane at ( +0.5 cm ,+0.5 cm ),

I 4 = −1 ⋅ ^z [ A ] crossing the z = 0 plane at ( +0.5 cm ,−0.5 cm),

MATLAB code:
1. clear all;  
2.   
3. % Define the permeability constant  
4. mu0 = 4*pi*1e-7;  
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. I1 = 1;  
10. I2 = -1;  
11. I3 = 1;  
12. I4 = -1;  
13.   
14. xI1 = -0.5; % xI1 = -0.5 cm  
15. yI1 = -0.5; % yI1 = -0.5 cm  
16.   
17. xI2 = -0.5; % xI2 = -0.5 cm  
18. yI2 = 0.5; % yI2 = 0.5 cm  
19.   
20. xI3 = 0.5; % xI3 = 0.5 cm  
21. yI3 = 0.5; % yI3 = 0.5 cm  
22.   
23. xI4 = 0.5; % xI4 = 0.5 cm  
24. yI4 = -0.5; % yI4 = -0.5 cm  
25.   
26. % Calculate distance from each grid point  
27. % to the point charge I1, I2, I3 and I4  
28. R1 = sqrt((x-xI1).^2+(y-yI1).^2);  
29. R2 = sqrt((x-xI2).^2+(y-yI2).^2);  
30. R3 = sqrt((x-xI3).^2+(y-yI3).^2);  
31. R4 = sqrt((x-xI4).^2+(y-yI4).^2);  
32.   
33. % Calculate x-component of the magnetic field  
34. B1x = 1e+4*mu0*I1.*(y-yI1)./(2*pi.*(R1).^2);  
35. B2x = 1e+4*mu0*I2.*(y-yI2)./(2*pi.*(R2).^2);  
36. B3x = 1e+4*mu0*I3.*(y-yI3)./(2*pi.*(R3).^2);  
37. B4x = 1e+4*mu0*I4.*(y-yI4)./(2*pi.*(R4).^2);  
38. Bx = B1x + B2x + B3x + B4x;  
39. % Calculate y-component of the magnetic field  
40. B1y = 1e+4*mu0*I1.*-(x-xI1)./(2*pi.*(R1).^2);  
41. B2y = 1e+4*mu0*I2.*-(x-xI2)./(2*pi.*(R2).^2);  
42. B3y = 1e+4*mu0*I3.*-(x-xI3)./(2*pi.*(R3).^2);  
43. B4y = 1e+4*mu0*I4.*-(x-xI4)./(2*pi.*(R4).^2);  
44. By = B1y + B2y + B3y + B4y;  
45.   
46. %Plot the B-field  
47. figure  
48. streamslice(x, y, Bx, By);  
49. axis([-2 2 -2 2]);  
50. hold on;  
51.   
52. title('Phuc - Anh     [I1 = 1; I2 = -1; I3 = 1; I4 = -1]');  
53.   
54.   
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:
 Four magnetic interact with each other.
 Four magnetic fields have the same magnitude

You might also like