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

Emt Matlab Coding

This document defines variables to calculate the magnetic field generated by a surface current. It defines the current density J, divides the current sheet into cells, then calculates the magnetic field contribution of each cell at a grid of plotting points and at a single point P by taking the cross product of the current density and position vectors. The x and y components of the magnetic field are plotted with quiver.

Uploaded by

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

Emt Matlab Coding

This document defines variables to calculate the magnetic field generated by a surface current. It defines the current density J, divides the current sheet into cells, then calculates the magnetic field contribution of each cell at a grid of plotting points and at a single point P by taking the cross product of the current density and position vectors. The x and y components of the magnetic field are plotted with quiver.

Uploaded by

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

clc; %clear the command window

clear; %clear all variables

J=2; %value of surface current


Js=J*[0 0 1]; %the vector of surface current

Zmin=-10; %coordinate of lowest z value on line


Zmax=10; %coordinate of maximum z value on line

NumberOfZDivisions=100; %number of cells in the z direction

dz=(Zmax-Zmin)/NumberOfZDivisions; %step in the z direction


dL=dz; %area of one subsection of line
XCellCenter=0;%just as origin
YCellCenter=0;

NumberOfXPlottingPoints=30; %number of plotting points along the x


axis,set by yourself.
NumberOfYPlottingPoints=30; %number of plotting points along the y axis
PlotXmin=-5; %lowest x value on the plot plane
PlotXmax=5; %maximum x value on the plot plane
PlotYmin=-5; %lowest z value on the plot plane
PlotYmax=5; %maximum z value on the plot plane
PlotStepX= (PlotXmax-PlotXmin)/(NumberOfXPlottingPoints-1);%plotting
step in the x direction
PlotStepY=(PlotYmax-PlotYmin)/(NumberOfYPlottingPoints-1); %plotting
step in the y direction
[XData,YData]=meshgrid(PlotXmin:PlotStepX:PlotXmax,
PlotYmin:PlotStepY:PlotYmax); %build arrays(matrix) of plot plane
PlotZ=0; %since xy plane so z equal zero
Bx=zeros(NumberOfXPlottingPoints,NumberOfYPlottingPoints); %x component
of field
By=zeros(NumberOfXPlottingPoints, NumberOfYPlottingPoints);%z component
of field
for m=1:NumberOfXPlottingPoints %repeat for all plot points in the x
direction
for n=1:NumberOfYPlottingPoints %repeat for all plot points in the y
direction
PlotX=XData(m,n); %x coordinate of current plot point
PlotY=YData(m,n); %y coordinate of current plot point
if ((PlotY==0)&(PlotX>=Xmin)&(PlotX<=Xmax)) % if the plotting point is
on the current sheet
Bx(m,n)=J/(4*pi); % we use the model of infinite current sheet
By(m,n)=0;
continue;
end
Rp=[PlotX PlotY PlotZ]; %poistion vector of observation points, for the
position of answer

for j=1:NumberOfZDivisions %repeat for all cells in the z direction,


100 to 1, then will stop.

ZCellCenter=Zmin+(j-1)*dz+0.5*dz; %Y center current subsection


Rc=[XCellCenter YCellCenter ZCellCenter]; %position vector of center of
current subsection, define line current
R=Rp-Rc; %vector pointing from current subsection to the current
observation point
norm_R=norm(R); %get the distance between the current surface element
and the observation point
R_Hat=R/norm_R; %unit vector in the direction of R
dH=(dL/(4*pi*norm_R*norm_R))*cross(Js,R_Hat); %this is the contribution
from current element
Bx(m,n)=Bx(m,n)+dH(1,1); %increment the x component at the current
observation point
By(m,n)=By(m,n)+dH(1,2); %increment the z component at the current
observation point
end %end of j loop
end %end of n loop
end %end of m loop

quiver(XData, YData, Bx, By);


xlabel('x(m)');%label x axis
ylabel('y(m)');%label y axis

%The following routing caculates the magnetic field at point P


P=[0 2 0];%position of point P
Hp=[0 0 0];%the magnetic field at point P

for j=1:NumberOfZDivisions %repeat for all cells in the y direction

ZCellCenter=Zmin+(j-1)*dz+0.5*dz; %Y center current subsection


Rc=[XCellCenter YCellCenter ZCellCenter]; %position vector of center of
current subsection
R=P-Rc; %vector pointing from current subsection to the current
observation point
norm_R=norm(R); %get the distance between the current surface element
and the observation point
R_Hat=R/norm_R; %unit vector in the direction of R
dH=(dL/(4*pi*norm_R*norm_R))*cross(Js,R_Hat); %this is the contribution
from current element
Hp=Hp+dH;
end %end of j loop

You might also like