0% found this document useful (0 votes)
44 views15 pages

Computational Electromagnetics-: Abstract

1. The document discusses calculating gradient, curl, and divergence of vector and scalar fields using MATLAB. It provides code to calculate these quantities and visualize the results. 2. Functions like gradient(), curl(), and divergence() are used to calculate derivatives of fields. Meshing, contour(), quiver(), and related functions are used to plot the fields and their derivatives in 2D and 3D. 3. The code examples calculate derivatives for various scalar and vector fields, and visualize the results to demonstrate gradient, curl, and divergence operations in computational electromagnetics using MATLAB.

Uploaded by

shreeshivaani28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views15 pages

Computational Electromagnetics-: Abstract

1. The document discusses calculating gradient, curl, and divergence of vector and scalar fields using MATLAB. It provides code to calculate these quantities and visualize the results. 2. Functions like gradient(), curl(), and divergence() are used to calculate derivatives of fields. Meshing, contour(), quiver(), and related functions are used to plot the fields and their derivatives in 2D and 3D. 3. The code examples calculate derivatives for various scalar and vector fields, and visualize the results to demonstrate gradient, curl, and divergence operations in computational electromagnetics using MATLAB.

Uploaded by

shreeshivaani28
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

COMPUTATIONAL ELECTROMAGNETICS-

ABSTRACT:
To know the various applications in the MATLAB and implementing
the operations such as Gradient ,divergence and curl of vector and scalar
using MATLAB .

PROGRAM:
1. Calculate gradient curl divergence
close all %closes all opened MATLAB figures
clear all %clear all the data in variable
clc %clear the command window syms x y
z %declares variable
u1=[x^2*y*z 0 x*z]; %variable u1 is assigned with (x^2yz)ax+(xz)az
d=curl(u1,[x,y,z]) %variables d is assigned with the curl
u2=[x^2*y*z 0 x*z]; %U2 variable is assigned with another vector
function
d1=divergence(u2,[x y z])%variable d1 is assigned with another vector
function U2.

u3=(x^2*y)+x*y*z; %U3 is assigned with scalar function


d2=gradient(u3,[x y z]) %d2 is assigned the gradient of the scalar
function U3

2. Gradient

close all %closes all opened MATLAB figures


clear all %clear all the data in variable clc
%clear the command window

[x,y] = meshgrid(-3:0.2:3); %2d array is created with x and y as the


dimensions
U1=x.*exp(-x.^2-y.^2); %U1 is assigned with scaler function.
surf(x,y,U1); %produces 3d plot of the scalar function xlabel('x')
%'x' is provided as the xlabel of the
plot. ylabel('y') %'y' is provided as the ylabel of the plot.
zlabel('z') %'z' is provided as the zlabel of the plot.

3.
close all %closes all opened MATLAB figures
clear all %clear all the data in variable clc
%clear the command window

[x,y]=meshgrid(-3:0.2:3); %2d array is created with x and y as the


dimensions.

u1=x.*exp(-x.^2-y.^2); %U1 is assigned with scaler function


[px,py]=gradient(u1); %The gradient value at different points of
the space is stored in a 2d array. figure %Used
to plot multiple plots contour(x,y,u1) %produces
3d plots of the field. hold on %used to the add a
plot to the same graph without deleting the existing plot.

quiver(x,y,px,py) %produces 2d plot of the field hold


off
xlabel('x') %'x' is provided as the xlabel ylabel('y')
%'y' is provided as the ylabel zlabel('z') %'z' is provided
as the zlabel

4.
close all
clear all clc
[x,y] = meshgrid(-8:0.2:8);
U1 = x.*y; surf(x,y,U1);
contour(x,y,U1);
xlabel('x') ylabel('y')
zlabel('z') OUTPUT:

1.
2.
3.
4.
INFERENCE:
1.

▪ In build function used to calculate the gradient,curl and divergence


of the given fields. ▪ close and clear all are used to close all the
opened figures and clear all the the data.

▪ from this we are calculating gradient,curl and divergence using


Matlab.

2.

▪ Used in creating 2d array with dimensions.(meshgrid)


▪ used in creating 3d plots.(surf)
▪ In labelling (xlabel(label_name),
ylabel(label_name),zlabel(label_name) > clc command clears the
command window.

3.

▪ Used in creating 2d array with dimensions.(meshgrid)


▪ used in creating 3d plots.(surf)
▪ In labelling (xlabel(label_name),
ylabel(label_name),zlabel(label_name)
▪ Plotting more that one .( figure,hold on ,quiver,hold off) ▪ clc
command clears the command window.

4.
Used to create gradient for the function x and y
ABSTRACT:
The following experiment is to define a vector field calculate and
visualize its divergence and curl through MATLAB.

PROGRAM:
1.
close all % closes all opened MATLAB figures. clear all
% clears all the data in the variables clc
% Clears the command window.

[x, y] = meshgrid(-1: 0.1: 1); % 2d matrix with x and y as dimensions


is created.
U1 = cos(x).*cos(y); % U1 is assigned with a scalar function
cos(x)cos(y)
[px, py] = gradient(U1); % Stores the gradient in a 2d matrix with px
and py as d imensions. figure contour(x,y,
U1) % 2d - plot of the scalar field. hold on quiver(x,y,px,py)
% Function to plot vectors. hold off xlabel("x") %
"x" is given as the xlabel of the plot
ylabel("y") % "y" is given as the ylabel of the plot

2.
close all % closes all opened MATLAB figures. clear all
% clears all the data in the variables. clc
% Clears the command window.

[x, y] = meshgrid(-1: 0.1: 1); % 2d matrix is created and with


dimensions x and y
U1 = cos(x.*y); % U1 is declared with a scalar function cos(xy)
[px,py] = gradient(U1) % 2d matrix is created with dimensions px and
py which stores the gradient of the scalar function. figure
contour(x,y, U1) % 2d - plot of the scalar field. hold on
quiver(x,y,px,py) % 2d - plot of the gradient of the scalar field.
hold off
xlabel("x") % "x" is given as the xlabel of the plot
ylabel("y") % "y" is given as the ylabel of the plot

3.
close all % closes all opened MATLAB figures. clear all % clears
all the data in the variables. clc % Clears the command window.
syms x y z % x y z variables are declared using syms command. [x,y]
= meshgrid(-2:0.2:2 , -2:0.2:2); % 2d matrix is created and with
dimensions x and y com_1 = -sin(x).*sin(y); % com_1 is initialized with
the x-component of the vector field.
com_2 = cos(x).*cos(y); % com_2 is initialized with the y-component
of the vector field. quiver(x, y, com_1, com_2) % 2-d plot of the
vector field.
d = divergence(x, y, com_1, com_2) % d is initialized with the
divergence of the vector field. hold on contour(x, y, d) % 2-d plot
of the divergence of the vector field. xlabel("x") % "x" is given
as the xlabel of the plot ylabel("y") % "y" is given as the ylabel
of the plot

4.
close all % closes all opened MATLAB figures. clear
all % clears all the data in the variables.
clc % Clears the command window. syms x y z % x y z
variables are declared using syms command. u1 = [y*sin(x*y) -x*sin(x*y)
0] % u1 is initialized with a vector field. d = divergence(u1, [x y
z]) % d is initialized with the divergence of the vector field.

[x, y] =meshgrid(-3:0.2:3); % 2d matrix is created and with


dimensions x and y com1 = y.*sin(x.*y); % com_1 is
initialized with the xcomponent of the vector field. com2 = -
x.*sin(x.*y); % com_2 is initialized with the ycomponent
of the vector field. quiver(x, y, com1, com2) % 2-d plot of
the vector field. d1 = divergence(x, y, com1, com2); % d1 is
initialized with divergence of the field through the components. hold
on contour(x, y, d1) % 2-d plot of the divergence of the
vector field. xlabel("x") % "x" is given as the
xlabel of the plot ylabel("y") % "y" is given as the
ylabel of the plot

5.
close all % closes all opened MATLAB figures. clear all
% clears all the data in the variables. clc %
Clears the command window.
syms x y z % x y z variables are declared using syms command.
u1 = [-y x 0]; % u1 is initialized with a vector field.
c1 = curl(u1, [x y z]) %c1 is initialized with the curl of the vector
field u1.

[x,y,z] = meshgrid(-2: 0.2: 2); % 3-d grid is produced with dimensions


x y z. com1 = -y;% com1 is initialized as the x component of the vector
field. com2 = x;% com2 is initialized as the y component of the vector
field. com3 = 0*% com3 is initialized as the z component of the vector
field. [px,py,pz] = curl(x,y,z,com1, com2, com3); % 2-d matrix with
entries px py pz is created to store the curl of the vector field at
every point (x y z)

quiver3(x,y,z,px, py, pz) %2-d plot of the curl of the vector


field with three variables is plotted using quiver3() function
xlabel("x") % "x" is given as the xlabel of the plot
ylabel("y") % "y" is given as the ylabel of the plot

OUTPUT:
1.
2.

3.
4.
5.
INFERENCE:
1.
• Gradient of the scalar function is calculated using gradient()
function.
• The 2-d plot of the gradient of the scalar function is obtained using
the quiver() function. Generally 2-d plot of any vector function is
plotted using quiver() function.

2.
• Gradient of the scalar function is calculated using gradient()
function.
• The 2-d plot of the given scalar function is obtained using
contour() function. Generally 2-d plot of any scalar function is
plotted using contour() function

3.
• The divergence of a given vector field can be calculated using the
divergence() function.
• The vector field can be visualized as a 2-d plot using the quiver()
function.

4.
• The divergence of a given vector field can be calculated using the
divergence() function.
• 2-d plot of the divergence of the vector field is plotted by the
contour() function.

5.
• Curl of a given vector field is obtained from curl() function.
• The curl of the vector field with 3 variables is visualized as a 2-d
plot using the quiver3() function.

You might also like