Magnetic field in a square loop 3D graph
7 views (last 30 days)
Show older comments
[EDIT: Fri May 20 22:28:13 UTC 2011 - Merged Comment - MKF]
Hello
I have problem with ploting 3d graph for magnetic field inside of square loop carrying current. My graph is pretty flat and that's not ok. Problem is I think with vectors which define graph x,y. I don't know what exactly is wrong so can someone make some markers what should I change. Thank you
Greetings from Slovenia
Here is the code of what I done till now
%clc; clear; close all;
vx = 0.1:0.2 : 10;
vy = 0.1:0.2 : 10;
[x,y] = meshgrid(vx,vy);
a = 10;
b = 10;
I = 300;
N = 4;
t = (4*3.14*I)/(4*3.14);
o = sqrt(y .^2 + x .^2);
p = sqrt(x .^2 + (b - y).^2);
r = sqrt((b - y).^2 + (a-x).^2);
s = sqrt((a-x).^2 + y.^2);
% z = N*t*((((y ./o)-((b-y)./p))/x+(((x./p)-((a-x)./r))/(b-y))+ ((((b-y)/r)-((y)/s))/(a-x))+ (((a-x)/s)-((x)/o))/(y)));
z = N*t*((((y ./o)-((b-y)./p))./x+(((x./p)-((a-x)./r))./(b-y))+ ((((b-y)./r)-((y)./s))./(a-x))+ (((a-x)./s)-((x)./o))./(y)));
figure;
mesh(x,y,z);
%plot3(x,y,z)
grid on;
%colorbar;
[Updated]
I changed structure and principal of getting values to how proecsm suggested
%drug nacin s tokovno daljico *4 pa zrotiran in pomnožen z N ovoji :)
%definicije vektorjev za risanje
vx = 1 : 15;
vy = 1 : 10;
[x1,y1] = meshgrid(vx,vy);
%konstante
mi0=4*pi*10^-7;
I=100;
%velikost okvirja
a=15;
b=10;
N=1;
%zanka za izračun B v okolici na matriki
for x=1:a
for y=1:b
B(x,y)=((N*mi0*I)/(4*pi*a))*(((b-y)/sqrt((b-y)^2+x^2))+(y/(sqrt(x^2+y^2))));
end
end
%Rotacija osnovne matrike za prispevke vseh 4 strani zanke
B1=rot90(B);
B2=rot90(B1);
B3=rot90(B2);
Bsk=N.*(B+B1+B2+B3);
figure;
mesh(x1,y1,Bsk);
grid on
I get the following error:
??? Error using ==> mesh at 80
Data dimensions must agree.
Error in ==> tokovna_daljica at 29
mesh(x1,y1,Bsk);
hm I don't see the problem, I defined vx and vy and gave enough room i think for graph to draw. How should I change the x1 and y1 to properly draw graph.
Thank you
3 Comments
Answers (4)
bym
on 17 May 2011
Ok, so I think I understand what you are doing. Your calculations for o,p,r,s are not needed. While the magnetic field is dependent on the radial distance from the wire, your problem is essentially 2d. So, for example, the wire at x=0, its radial distance is just the y coordinate. You can calculate the magnetic field for each of the 4 wires and add them up (accounting for sign changes due to current flow)
[EDIT] Hi Denis
This is what I did
clc; clear; close all;
vx = .1:0.2 : 10;
vy = .1:0.2 : 10;
[x,y] = meshgrid(vx,vy);
cur = 300;
mu = 4*pi*10^-7; % permeability of free space
z1 = mu*cur./(2*pi*y);
z2 = mu*cur./(2*pi*x);
z3 =-mu*cur./(2*pi*(y-10));
z4 =-mu*cur./(2*pi*(x-10));
z = z1+z2+z3+z4;
mesh(x,y,z)
figure
zr = z1+rot90(z1)+rot90(z1,2)+rot90(z1,3);
mesh(x,y,zr)
I checked your use of rot90 and it worked for square but not for rectangular loops
0 Comments
Teja Muppirala
on 6 Jun 2011
Whatever you are doing with FOR loops is not necessary. MATLAB can work with matrices much more simply:
I = 100;
[X,Y] = meshgrid(0:0.01:1);
COS_TH = X./sqrt(X.^2 + Y.^2);
COS_PH = (1-X)./sqrt((1-X).^2 + Y.^2);
d = Y;
B = I * 1e-7 * (COS_TH + COS_PH)./d;
B = B + flipud(B) + rot90(B,1) + rot90(B,-1);
imagesc(B); axis equal
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!