Question

I have to plot in the xz plane the magnetic field of a dipole in matlab....

I have to plot in the xz plane the magnetic field of a dipole in matlab. The dipole is centered in (0,0) and has a magnetic dipole moment M parallel to the z axis. How can I achieve this?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function h=lforce2d(n,color)
% LFORCE2D: Generates a 2D polar plot of n-lines of force of the Gecentric Axial Magnetic Dipole

n=10;
color=[1 0 0];
rad = pi/180;
theta = (0:5:360)'*rad;
A = 2:n;
r = sin(theta).^2*A;
nC = size(r,2);
u = ones(1,nC);
ct = cos(theta)*u;
st = sin(theta)*u;

x = r.*st;
y = r.*ct;

figure;
R = max(x(:))/8;
axis equal;
h = plot(x,y,'r');
[nR,nC] = size(x);

for iR=2:6:floor(nR/2)
for jC=1:2:nC;
p1 = [x(iR-1,jC) -y(iR-1,jC)];
p2 = [x(iR,jC) -y(iR,jC)];
hv=plotvec(p1,p2,'r');
end
end

for iR=floor(nR/2)+2:6:nR;
for jC=1:2:nC;
p1 = [x(iR-1,jC) y(iR-1,jC)];
p2 = [x(iR,jC) y(iR,jC)];
hv=plotvec(p1,p2,'r');
end
end


hold on;
hc = fcircle(R,[0,0],'r');
hv = plotvec([0 R/2], [0 -R/2],'r');
h=plot([0 0],[R/2, -R/3],'r','LineWidth',3);

title('Magnetic Dipole Field','FontSize',15);
hold off;
grid on;

h=[h;hc];
  

function hh=fcircle(r,o,s)
% FCIRCLE - draws a filled cirlce

axis equal;
if nargin==2
h=patch(r*cos(phi)+o(1),r*sin(phi)+o(2),'');
else
h=patch(r*cos(phi)+o(1),r*sin(phi)+o(2),s);
end
set(h,'edgec',get(h,'facec'));
set(h,'user',{'fcircle',r,o});
if nargout,hh=h;end

function h=plotvec(p1,p2,linespec)
% PLOTVEC - Draws a vector.

if nargin==2,linespec='';end
held=ishold;hold on
x=[p1(1) p2(1)];
y=[p1(2) p2(2)];
dx=diff(x);
dy=diff(y);
hh(1)=plot(x,y,linespec);
ax=axis;
lx=diff(ax(1:2))*15e-3;
ly=diff(ax(3:4))*10e-3;
phi=atan2(dy,dx);
hd=rotate2([-lx 0 -lx;ly 0 -ly],[0;0],phi);
col=get(hh(1),'color');
hh(2)=patch(hd(1,:)+p2(1),hd(2,:)+p2(2),col);
set(hh(2),'edgec',col)
set(hh(1),'user',{'vector',p1,p2,hh(2)})
set(hh(2),'user',{'vector',p1,p2,hh(1)})
if ~held,hold off,end
if nargout,h=hh;end

function n_p=rotate2(points,origo,phi)
%ROTATE2 rotate points in 2 dimensions.

A=[cos(phi) -sin(phi);sin(phi) cos(phi)];
n_p=A*points+origo*ones(1,size(points,2));

Add a comment
Know the answer?
Add Answer to:
I have to plot in the xz plane the magnetic field of a dipole in matlab....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • matlab of Plot the E-plane and H-plane radiation pattern of a Hertzian dipole in far field.

    matlab of Plot the E-plane and H-plane radiation pattern of a Hertzian dipole in far field.

  • 4. Magnetic Dipole Moment on a PEC Sphere: In HW 4-Problem 5, you found the electric dipole momen...

    4. Magnetic Dipole Moment on a PEC Sphere: In HW 4-Problem 5, you found the electric dipole moment for a metal sphere of radius a in a uniform electric field. In this problem you will find the magnetic dipole moment for the same metal sphere but now in a uniform magnetic field, Hext-Hext2. Note:Assume that the sphere is centered at the origin of a spherical coordinate system. Express Hext in spherical coordinates. To find the magnetic field that is induced...

  • 2. RFID Tag Magnetic field: Consider a square loop of wire that lies in the x-y plane and carries...

    2. RFID Tag Magnetic field: Consider a square loop of wire that lies in the x-y plane and carries an electric current lo. The center of the loop is located at the origin and each side has length a. The current flows in a counter-clockwise direction as shown in the figure below Note*: This is a common design for an RFID tag's antenna, we will analyze RFID tag detection at a later time. a) Using Biot-Savart's law, find an expression...

  • A magnetic dipole is in a nonuniform magnetic field The dipole will always be attracted to...

    A magnetic dipole is in a nonuniform magnetic field The dipole will always be attracted to the region with a stronger magnetic field always be repelled from the region with a stronger magnetic field might be repelled, but will eventually flip over and be attracted to the region with a stronger magnetic filed might be attracted but could flip over and then be repelled from the region with a stronger magnetic field For distance d m uch larger than the...

  • 4. (2 pts) Find the exact magnetic field a distance z above the center of a...

    4. (2 pts) Find the exact magnetic field a distance z above the center of a rectangle lying in the xy plane, centered on the origin, with side of length a in the x direction and side of length b in the y direction, carrying a current. Verify that it reduces to the field of a dipole with the appropriate dipole moment when za and z»b.

  • Don't need more information 3. The field of a magnetic dipole located at the origin and...

    Don't need more information 3. The field of a magnetic dipole located at the origin and oriented in the ż direction can be written as: B om 4ar3 (2 cos 0f +sin 00), where m is the magnitude of the magnetic dipole moment. a) Calculate the flux of the magnetic field through 2 direction, located at z=a. b) Calculate the flux of the magnetic field through a square of side length 2a oriented in the à direction, located at a...

  • (S3) A dipole with dipole moment p = f(i +ì) is placed in a region with...

    (S3) A dipole with dipole moment p = f(i +ì) is placed in a region with uniform electric field Ē = Eoj. (i) What is the magnitude of the dipole moment vector? (ii) How much energy is required to reorient the dipole parallel to the positive x axis?

  • 1. Magnetic Field Generated by a Current in a Wire Under steady-state conditions, a magnetic fiel...

    1. Magnetic Field Generated by a Current in a Wire Under steady-state conditions, a magnetic field B has curlB in a region where there is no current. We study the steady-state magnetic field B due to a constant current in an infinitely long straight thin wire. The magnitude of the magnetic field at a point depends only on the distance from the wire and its direction is tangent to the circle around the wire and determined by the right-hand rule....

  • Consider a paramagnetic system of N elementary dipoles (with dipole moment μ) that can only have ...

    Using MATLAB Consider a paramagnetic system of N elementary dipoles (with dipole moment μ) that can only have states of parallel ↑ or antiparallel ↓ to the applied magnetic field B. The energies associated with each dipole is ±μ-B, the lower energy state being when the dipole is parallel to the B field. The macrostate state of the system will be defined by Nt, or equivalently, the total energy: The multiplicity of a given macrostate of a paramagnet is given...

  • normal 2. RFID Tag Magnetic field: Consider a square loop of wire that lies in the...

    normal 2. RFID Tag Magnetic field: Consider a square loop of wire that lies in the x-y plane and carries an electric current lo. The center of the loop is located at the origin and each side has length a. The current flows in a counter-clockwise direction as shown in the figure below. Note*: This is a common design for an RFID tag's antenna, we will analyze RFID tag detection at a later time. Using Biot-Savart's law, find an expression...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT