You are on page 1of 42

LABORATORY MANUAL

2021-22

ELECTROMAGNETIC FIELD
(3140912)
B.E. 4th SEMESTER

DEPARTMENT OF ELECTRICAL ENGINEERING


L. D. COLLEGE OF ENGINEERING,
AHMEDABAD

1|P a ge
Department Vision
To Foster Learning Environment for Electrical Engineering
Education having High Technical Skills, Ethical Values and
Overall Global Competence.

Department Mission
To provide high quality graduate program in Electrical Engineering to
prepare students for
1. Better Employability, Startups and Entrepreneurship.
2. A professional career with essential technical and managerial
skills.
3. Collaboration with industries through research and innovation.
4. Other avenues for higher education.
5. Adapting to change in technology and apply the same for
the benefits of society at large.
Program Educational Outcomes (PEOs)
PEO 1: To create better learning environment to develop
entrepreneurship capabilities in various areas of Electrical
Engineering with superior efficiency, productivity, cost
effectiveness and technological empowerment of human
resource.

PEO 2: To inculcate research capabilities in different areas of


Electrical Engineering to identify, comprehend and solve
problems and adapt themselves in a world of constantly
evolving technology.

PEO 3: To generate high standards of moral and ethical values among


the graduates, this will help in transforming them as
responsible citizen of the nation.
SR PROGRAM DATE SIGNATURE
NO.
1.1 To study and understand Dot Product and its
applications using MATLAB.
1.2 To study and understand Cross Product and
its applications using MATLAB.
2.1 To understand Conversion of Cartesian
Coordinates into Cylindrical and Spherical
Coordinates and vice versa using MATLAB.

2.2 To understand Conversion of Cartesian


system vectors into Cylindrical and Spherical
system vectors and vice versa using
MATLAB.
3.1 To calculate force between two charges using
MATLAB.
3.2 To calculate Electric Field due to a charge at
a given point using MATLAB.
4.1 To calculate Electric Field due to Uniform
Line Charge Configurations at a given point
using MATLAB.
4.2 To calculate Electric Field due to Uniform
Sheet Charge Configurations at a given point
using MATLAB.
5 To understand the concept of Divergence and
verify Divergence theorem using MATLAB.

6 To calculate the potential difference between


two points using MATLAB.
7 To implement Laplacian operator using
MATLAB.
8 To verify Biot-Savart Law using MATLAB.
9 To understand and implement Curl operator
using MATLAB.
10 To verify Stoke’s theorem using MATLAB.

2|Page
Practical: 1.1 Date:

Aim: To study and understand Dot Product and its applications using MATLAB.

Theory:
C = dot(A,B) returns the scalar product of the vectors A and B. A and B must be
vectors of the same length. When A and B are both column vectors, dot(A,B) is
the same as A*B.

Program:

%Dot Product and its Applications

clc;
a=input('coordinates of point A:')
b=input('coordinates of point B:')
c=input('coordinates of point C:')
Rab=b-a;
Rac=c-a;
Ms=dot(Rab,Rab);
Ms1=dot(Rac,Rac);
Mr=sqrt(Ms);
Mr1=sqrt(Ms1);

%unit vector
display('The unit vector along AC is')
Racu=Rac/Mr1

%scalar projection
display('The scalar projection of AB on AC is')
sp=dot(Rab,Racu)

%Vector Projection
display('The vector projection of AB on AC is')
vp=sp*Racu

%angle between Rab and Rbc


display('The angle between AB and AC is')
ang=acosd(dot(Rab,Rac)/(Mr1*Mr))

3|P a ge
Output:

Conclusion:

Signature:

4|P a ge
Practical: 1.2 Date:

Aim: To study and understand Cross Product and its applications using
MATLAB.

Theory:
C = cross(A,B) returns the cross product of the vectors A and B. That is,
C=A*B. A and B must be 3-element vectors. If A and B are multidimensional
arrays, cross returns the cross product of A and B along the first dimension of
length 3.

Program:

%Cross Product and its applications

clc;
a=input('Enter coordinates of point A:')
b=input('Enter coordinates of point B:')
c=input('Enter coordinates of point C:')
Rab=b-a;
Rbc=c-a;
Ms=dot(Rab,Rab);
Ms1=dot(Rac,Rac);
Mr=sqrt(Ms);
Mr1=sqrt(Ms1);

%cross product
disp('The cross product of AB and AC is:')
CP=cross(Rab,Rac)

%Area
Ms2=dot(CP,CP);
Mr2=sqrt(Ms2);
disp('The area of triangle ABC is:')
Area=0.5*Mr2

%unit vector along cross product


disp('The unit vector normal to the triangle is:')
Anu=CP/Mr2

5|P a ge
Output:

Conclusion:

Signature:
6|P a ge
Practical: 2.1 Date:

Aim: To understand Conversion of Cartesian Coordinates into Cylindrical and


Spherical Coordinates and vice versa using MATLAB.

Theory:

1. [THETA,RHO,Z] = cart2pol(X,Y,Z) transforms three-dimensional Cartesian


coordinates stored in corresponding elements of arrays X, Y, and Z, into
cylindrical coordinates. THETA is a counter clockwise angular displacement
in radians from the positive x-axis, RHO is the distance from the origin to a
point in the x-y plane, and Z is the height above the x-y plane. Arrays X, Y,
and Z must be the same size (or any can be scalar).

2. [THETA,PHI,R] = cart2sph(X,Y,Z) transforms Cartesian coordinates stored


in corresponding elements of arrays X, Y, and Z into spherical coordinates.
Azimuth THETA and elevation PHI are angular displacements in radians
measured from the positive x-axis, and the x-y plane, respectively; and R is
the distance from the origin to a point. Arrays X, Y, and Z must be the same
size (or any of them can be scalar).

3. [X,Y,Z] = pol2cart(THETA,RHO,Z) transforms the cylindrical coordinate


data stored in corresponding elements of THETA, RHO, and Z to three-
dimensional Cartesian, or coordinates. The arrays THETA, RHO, and Z
must be the same size (or any can be scalar). The values in THETA must be
in radians.

4. [X,Y,Z] = sph2cart(THETA,PHI,R) transforms the corresponding elements


of spherical coordinate arrays to Cartesian, or xyz, coordinates. THETA,
PHI, and R must all be the same size (or any of them can be scalar). THETA
and PHI are angular displacements in radians from the positive x-axis and
from the x-y plane, respectively.

7|P a ge
1. Program: Output:

%Cartesian to Cylindrical

clear all;
a=input('Enter coordinates in
Cartesian system:')

%conversion from cartesian to


cylindrical
disp('The Cylindrical Coordinates
are:')
[F,P,Z]=cart2pol(a(1),a(2),a(3));
RHO=P
PHI=F*180/pi
Z

2. Program: Output:

%Cylindrical to Cartesian

clear all;
a=input('Enter coordinates in
Cylindrical system:')

%Conversion from Cylindrical to


Cartesian
disp('The Cartesian Coordinates
are:')
[X,Y,Z]=pol2cart(a(2),a(1),a(3))

8|P a ge
3. Program: Output:

%Cartesian to Spherical

clear all;
a=input('Enter coordinates in Cartesian
system:')

%conversion from cartesian to Spherical


disp('The Spherical Coordinates are:')
R=sqrt((a(1)^2)+ (a(2)^2)+ (a(3)^2))
THETA=acosd(a(3)/(sqrt((a(1)^2)+
(a(2)^2)+ (a(3)^2))))
PHI=atand(a(2)/a(1))

4. Program: Output:

%Spherical to Cartesian

clc;
a=input('Enter coordinates in Spherical
system:')

%Conversion from Spherical to Cartesian


disp('The Cartesian Coordinates are:')
X=a(1)*sind(a(2))*cosd(a(3))
Y=a(1)*sind(a(2))*sind(a(3))
Z=a(1)*cosd(a(2))

Conclusion:

Signature:
9|P a ge
Practical: 2.2 Date:

Aim: To understand Conversion of Cartesian system vectors into Cylindrical


and Spherical system vectors and vice versa using MATLAB.

Theory:

For converting Cartesian to Cylindrical Co-ordinates and vice versa:


x=rcos ∅ y=rsin ∅ z=z
⍴=√� 2 + � 2 ∅=tan−1 z=z

Dot product of unit vectors of Cartesian and Cylindrical Coordinate Systems:


a⍴ aØ az
ax cos ∅ − sin ∅ 0
ay sin ∅ cos ∅ 0
az 0 0 1

For converting Cartesian to Spherical Coordinates and vice versa:


x=rsin cos ∅ y=rcos 𝜃 cos ∅ z=rcos 𝜃

r=√� 2 + � 2 θ=cos −1 ∅=tan−1


Dot product of unit vectors of Cartesian and Spherical Coordinate Systems:


ar aϴ aØ
ax sin θ cos ∅ cos θ sin ∅ − sin ∅
ay sin θ sin ∅ cos θ cos ∅ cos∅
az cos θ − sin θ 0

10 | P a g e
1. Program: Output:

%Conversion of Cartesian vector into


Cylindrical Vector
clc;
A=input('Enter the coefficients of
cartesian vector:')
B=input('Enter the cartesian point
for conversion of vector:')

%Converting point from Cartesian to


cylindrical
[phi,Rho,Z]=cart2pol(B(1),B(2),B(3));
%Making The Dot Table
disp('The Dot Table Matrix is:')
%Converting The vector
D=[cos(phi) -sin(phi) 0;sin(phi)
cos(phi) 0; 0 0 1]
disp('The coefficients of Cylindrical
Vector are:')
CV=A*D

2. Program: Output:
%Conversion of Cylindrical vector
into Cartesian Vector
clc;
A=input('Enter the coefficients of
Cylindrical vector:')
B=input('Enter the Cylindrical point
for conversion of vector:')
phi=B(2);

%Making The Dot Table


disp('The Dot Table Matrix is:')
%Converting The vector
D=[cos(phi) sin(phi) 0;-sin(phi)
cos(phi) 0; 0 0 1]
disp('The coefficients of Cylindrical
Vector are:')
CV=A*D

11 | P a g e
3. Program: Output:

%Conversion of Cartesian vector into


Spherical Vector
clc;
A=input('Enter the coefficients of
cartesian vector:')
B=input('Enter the cartesian point
for conversion of vector:')

%Converting point from Cartesian to


Spherical
R=sqrt(dot(B,B));
T=acosd(B(3)/R);
phi=atand(B(2)/B(1));

%Making The Dot Table


disp('The Dot Table Matrix is:')

%Converting The vector D=[sind(T)*cosd(phi)


cosd(T)*cosd(phi) -
sind(phi);sind(T)*sind(phi) cosd(T)*sind(phi)
cosd(phi);cosd(T) -sind(T) 0]
disp('The coefficients of Spherical Vector are:')
SV=A*D

4. Program: Output:

%Conversion of Spherical vector into


Cartesian Vector
clc;
A=input('Enter the coefficients of
Spherical vector:')
B=input('Enter the Spherical point
for conversion of vector:')
R=B(1);
T=B(2);
phi=B(3);
%Making The Dot Table
disp('The Dot Table Matrix is:')
D=[sind(T)*cosd(phi)
cosd(T)*cosd(phi) -
sind(phi);sind(T)*sind(phi)
cosd(T)*sind(phi) cosd(phi);cosd(T) -
sind(T) 0]

%Converting The vector


disp('The coefficients of Cartesian Vector are:')
CV=A*(D')

12 | P a g e
Conclusion:

Signature:

13 | P a g e
Practical: 3.1 Date:

Aim: To calculate force between two charges using MATLAB.

Theory:
Coulomb's law or Coulomb's inverse-square law, is a law of physics that
describes force interacting between static electrically charged particles. In its
scalar form the law is:
1 � 1∗ � 2
F= 4𝜋�� �2

where q1 and q2 are the signed magnitudes of the charges


r is the distance between the charges
ε is the permittivity of the medium
ε=8.854*10-12 C2N-1m-2 for free space

Program:

%Calculation of force between two charges

clc
e=input('Enter the value of epsilon:')
q1=input('Enter the value of charge1:')
q2=input('Enter the value of charge2:')
a1=input('enter the value of position1:')
a2=input('enter the value of position2:')

%Calculation of Unit Vector


disp('The vector joining both positions r12 is:')
r12=a2-a1
disp('The distance between both charges is:')
modr12=sqrt(r12(1)*r12(1)+r12(2)*r12(2)+r12(3)*r12(3))

modr13=modr12*modr12*modr12;

%Calculation of Force
disp('Force on charge 2 due to 1 is:')
F=(q1*q2*r12)/(4*3.14*e*modr13)

14 | P a g e
Output:

Conclusion:

Signature:

15 | P a g e
Practical: 3.2 Date:

Aim: To calculate Electric Field due to a charge at a given point using


MATLAB.

Theory:
The magnitude of the electric field E can be derived from Coulomb's law. By
choosing one of the point charges to be the source, and the other to be the test
charge, it follows from Coulomb's law that the magnitude of the electric field E
created by a single source point charge q at a certain distance from it r in
vacuum is given by:
1 �
F= 4𝜋�� � 2

Program:

%Calculation of field due to point charges

clear all
e=input('Enter the value of epsilon:')
q1=input('Enter the value of charge1:')
q2=input('Enter the value of charge2:')
a1=input('Enter the value of position1:')
a2=input('Enter the value of position2:')
a3=input('Enter the point at which total field is to be
calculated:')

%Calculating Unit Vectors


r13=a3-a1
r23=a3-a2
modr13=sqrt(r13(1)*r13(1)+r13(2)*r13(2)+r13(3)*r13(3));
modr23=sqrt(r23(1)*r23(1)+r23(2)*r23(2)+r23(3)*r23(3));
cu1=modr13*modr13*modr13;
cu2=modr23*modr23*modr23;

%Calculation of field
E13 = (q1*r13)/(4*3.14*e*cu1);
E23 = (q2*r23)/(4*3.14*e*cu2);
disp('The field at the given point is:')
E=E13+E23

16 | P a g e
Output:

17 | P a g e
Conclusion:

Signature:
18 | P a g e
Practical: 4.1 Date:

Aim: To calculate Electric Field due to Uniform Line Charge Configurations at


a given point using MATLAB.

Theory:
The Electric Field Intensity due to a Uniform infinite line charge configuration
is given as
⍴ ā
F=
2𝜋�� r

where ⍴ is the line charge density


r is the distance to the given point
ε is the permittivity of the medium
ε=8.854*10-12 C2N-1m-2 for free space
ā is the unit vector along the distance r

Program:

%Calculation of Electric Field Intensity due to line charge


configurations
clear all
a=input('Enter line charge density of line along xaxis')
b=input('Enter line charge density of line along yaxis')
x=input('Enter the point at which to find electric field
density')

%Field due to line charge along x axis


rx=[0 x(2) x(3)];
Ex=a*rx/[2*3.14*8.854*(1e-12)*dot(rx,rx)];

%Field due to line charge along y axis


ry=[x(1) 0 x(3)];
Ey=b*ry/[2*3.14*8.854*(1e-12)*dot(ry,ry)];

%Resultaant Field
disp('The electric field intensity is:')
E=Ex+Ey

19 | P a g e
Ouput:

Conclusion:

Signature:
20 | P a g e
Practical: 4.2 Date:

Aim: To calculate Electric Field due to Uniform Sheet Charge Configurations


at a given point using MATLAB.

Theory:
The Electric Field Intensity due to a Uniform infinite line charge configuration
is given as

F=
ā2𝜀
where ⍴ is the line charge density
r is the distance to the given point
ε is the permittivity of the medium
ε=8.854*10-12 C2N-1m-2 for free space
ā is the unit vector perpendicular to the surface of the sheet

Program:
%Calculation of Electric Field Intensity due to uniform sheet
charge configurations
clear all
p1=input('Sheet charge density of sheet 1:')
r1=input('Position of sheet 1:')
p2=input('Sheet charge density of sheet 2:')
r2=input('Position of sheet 2:')
p3=input('Sheet charge density of sheet 3:')
r3=input('Position of sheet 3:')
p=input('Enter the point at which to find electric field
density:')

%Field due to Sheet 1


a1=[0 0 p(3)-r1];
E1=p1*a1/[2*8.854*(1e-12)*sqrt((p(3)-r1)*(p(3)-r1))];

%Field due to Sheet 2


a2=[0 0 p(3)-r2];
E2=p2*a2/[2*8.854*(1e-12)*sqrt((p(3)-r2)*(p(3)-r2))];

%Field due to Sheet 3


a3=[0 0 p(3)-r3];
E3=p3*a3/[2*8.854*(1e-12)*sqrt((p(3)-r3)*(p(3)-r3))];

%Resultant Field
disp('The Electric Field Intensity is:')
E=E1+E2+E3

21 | P a g e
Output:

22 | P a g e
Conclusion:

Signature:

23 | P a g e
Practical: 5 Date:

Aim: To understand the concept of Divergence and verify Divergence theorem


using MATLAB.

Theory:
Divergence theorem states that the integral of normal component of any vector
field over a closed surface is equal to the integral of the Divergence of that vector
field throughout the volume enclosed by that closed surface.
∭ (𝛁 ⋅ ��) ⅆ𝑉 = ∯𝐅 ⋅ ⅆ𝐒
𝑉 �

Program:

%Program to prove divergence theorem

clc;

%Defining the variable x,y,z


x=sym('x');
y=sym('y');
z=sym('z');

%Limit declaration

x1=input('Enter the lower limit of x:');


x2=input('Enter the higher limit of x:');
y1=input('Enter the lower limit of y:');
y2=input('Enter the higher limit of y:');
z1=input('Enter the lower limit of z:');
z2=input('Enter the higher limit of z:');

%Proving LHS
V=input('Input the Vector Quantity:');
Vx=V(1)
Vy=V(2)
Vz=V(3)

Divx = diff(Vx,x)
Divy = diff(Vy,y)
Divz = diff(Vz,z)

24 | P a g e
disp('Your divergence of given vector is:')

div=Divx+Divy+Divz

div1=int(div,x,x1,x2);
div2=int(div1,y,y1,y2);
div3=int(div2,z,z1,z2);

disp('This is LHS of divergence theorem:')


LHS=div3

%Proving RHS

Sidex1=0;
Sidex2=0;
Sidey1=0;
Sidey2=0;
Sidez1=0;
Sidez2=0;

disp('At x=0')
Sidex1=0

disp('At x=1')

Sidex2=int(Vx,y,y1,y2);
Sidex2=int(Sidex2,z,z1,z2);

Sidex2=Sidex2/x

disp('At y=0 and y=-2')

Sidey1=0
Sidey2=0

disp('No z component present:')

Sidez1=0
Sidez2=0

RHS=Sidex1+Sidex2+Sidey1+Sidey2+Sidez1+Sidez2

disp('LHS = RHS Hence divergence theorem is proved.')

25 | P a g e
Output:

26 | P a g e
Conclusion:

Signature:
27 | P a g e
Practical: 6 Date:

Aim: To calculate the potential difference between two points using MATLAB.

Theory:
The potential difference between two points A and B at radial distances 𝒓� and
𝒓� from a point charge Q is given by,

𝑸 (� �
𝑽�� = − )
𝟒��𝝐� 𝒓 � 𝒓 �

Program:
%Program to find potential difference between two
points

clc;
clear all;

%Taking the inputs

Q=input('Enter the value of Q')


Ra=input('Enter the value of Ra')
Rb=input('Enter the value of Rb')

%Calculating the potential difference

Vab=(Q/(4*pi*8.854*(1e-12)))*((1/Ra)-(1/Rb));

%Display

disp('Potential differnce is:')


Vab

28 | P a g e
Output:

Conclusion:

Signature:

29 | P a g e
Practical: 7 Date:

Aim: To implement Laplacian operator using MATLAB.

Theory:
The “double del” operator or “Del squared” operator is also called the Laplacian
Operator.
𝜕 2𝜓 𝜕 2𝜓 𝜕 2𝜓
𝛁 ⋅ �� = + +
���2 �� � ���2
2

Program:

%Program to find Laplacian of any Scalar Quantity


clc;

%Defining the variable x,y,z


syms x
syms y
syms z

v=input('Input the scalar Quantity');

vx=diff(diff(v,x),x)

vy=diff(diff(v,y),y)

vz=diff(diff(v,z),z)

disp('Your Laplacian operator is:')

%The answer of the laplacian operator

L=vx+vy+vz

30 | P a g e
Output:

Conclusion:

Signature:
31 | P a g e
Practical: 8 Date:_

Aim: To verify Biot Savart’s Law using MATLAB.

Theory:
The law of Biot-Savart states that at any point P the magnitude of the magnetic
field intensity produced by the differential element is proportional to the product
of the current, the magnitude of the differential length, and the sine of the angle
lying between the filament and a line connecting the filament to the point P at
which the field is desired; also, the magnitude of the magnetic field intensity is
inversely proportional to the square of the distance from the differential element
to the point P.
� ⅆ𝐿 × 𝑎�
ⅆ�
4���
Program:
2
clc; =
clear all;

%Taking the inputs

IdL=input('Enter the value of IdL:')


P1=input('Enter the value of P1:')
P2=input('Enter the value of P2:')

%Calculating the magnetic field intensity

R=[P2(1)-P1(1) P2(2)-P1(2) P2(3)-P1(3)]


magR=sqrt((R(1))^2+(R(2))^2+(R(3))^2)
aR=R
dH=(cross(IdL,aR))/(4*pi*(magR)^3)

32 | P a g e
Output:

33 | P a g e
Conclusion:

Signature:
34 | P a g e
Practical: 9 Date:

Aim: To understand and implement Curl operator using MATLAB.

Theory:
The curl of any vector is a vector, and any component of the curl is given by
thelimit of the quotient of the closed line integral of the vector about a small
path in a plane normal to that component desired and the area enclosed, as the
path shrinks to zero.

∮ � ∙ ⅆ𝑳
∇ × � = lim
∆�→0 ∆�

Program:

%Program to find curl of any vector quantity


clc;

%Defining the variable x,y,z


x=sym('x');
y=sym('y');
z=sym('z');

%Taking the input


V=input('Input the Vector Quantity:');
Vx=V(1)
Vy=V(2)
Vz=V(3)

%Calculating the Curl


Curlx = diff(Vz,y)-diff(Vy,z);
Curly = diff(Vx,z)-diff(Vz,x);
Curlz = diff(Vy,x)-diff(Vx,y);

disp('The Curl of given vector is:')

Curl=[ Curlx Curly Curlz ]

35 | P a g e
Output:

Conclusion:

Signature:
36 | P a g e
Practical: 10 Date:

Aim: To verify Stoke’s theorem using MATLAB.

Theory:
Stoke’s Theorem states that the integration of any vector around a closed path is
always equal to the integration of the curl of that vector throughout the surface
enclosed by that path.

∫ 𝛁 × 𝐅 ⋅ ⅆ𝐒 = ∮ 𝐅 ⋅ ⅆ𝐫
� 𝐶

Program:

%Program to find curl of any vector quantity


clc;

%Defining the variable x,y,z


x=sym('x');
y=sym('y');
z=sym('z');

%Limit declaration

x1=input('Enter the lower limit of x:');


x2=input('Enter the higher limit of x:');
y1=input('Enter the lower limit of y:');
y2=input('Enter the higher limit of y:');
z1=input('Enter the lower limit of z:');
z2=input('Enter the higher limit of z:');

V=input('Input the Vector Quantity:');


Vx=V(1)
Vy=V(2)
Vz=V(3)

Curlx = diff(Vz,y)-diff(Vy,z)
Curly = diff(Vx,z)-diff(Vz,x)
Curlz = diff(Vy,x)-diff(Vx,y)

disp('Curl of given vector is:')


37 | P a g e
Curl=[ Curlx Curly Curlz ]

%LHS

LHS=int(Curlz,x,x1,x2);

disp('This is LHS of divergence theorem:')

LHS=int(LHS,y,y1,y2)

%RHS
Line1=0;
Line2=0;
Line3=0;
Line4=0;

Vx=-Vx/y;
Line1=int(Vx,x,x1,x2)

Line2=int(Vy,y,y1,y2)

Line3=Line1

Line4=-Line2

disp('This is LHS of divergence theorem:')

RHS=Line1+Line2+Line3+Line4

disp('LHS = RHS hence Stokes theorem is proved.')

38 | P a g e
Output:

39 | P a g e
Conclusion:

Signature:
40 | P a g e

You might also like