Magnetic field in a square loop 3D graph

조회 수: 7 (최근 30일)
denis leskovar
denis leskovar 2011년 5월 17일
[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
bym
bym 2011년 5월 18일
also, why is flat in the center not ok?
denis leskovar
denis leskovar 2011년 5월 21일
because its not, in the middle yes but not all around in the middle of square loop

댓글을 달려면 로그인하십시오.

답변 (4개)

bym
bym 2011년 5월 17일
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

denis leskovar
denis leskovar 2011년 5월 21일
I figured squarnes later in the night :). Problem with your script is that you took equations for wires with no final lenght, so there is lack of (cos a - cos a2). I'll work on my graph tomorrow beacuse it's gona rain all day :). I'll keep you all updated
thank you

denis leskovar
denis leskovar 2011년 6월 6일
After some brainstorming there is my final solution, but I am not happy with it because the matrix isn't symetrical on either axis. I can't find mistake which causes this.
here is the code, don't bother with comments
%drug nacin s tokovno daljico *4 pa zrotiran in pomnoen z N ovoji
clc; clear; close all;
%konstante
mi0=4*pi*10^(-7);
I=100;
%velikost okvirja
a=30;
b=55;
%stevilo ovojev
N=10;
%definicije vektorjev za risanje
vx = 1 : (a-2);
vy = 1 : (b-2);
[x1,y1] = meshgrid(vx,vy);
%zanka za krajso stranico
for y=0:b
for x=0:a
Bs0(y+1,x+1)=((N*mi0*I)/(4*pi*(x)))*(((b-y)/sqrt((b-y)^2+x^2))+(y/(sqrt(x^2+y^2))));
end
end
%zanka za daljso stranico
for i=0:a
for j=0:b
Bdzacasna(i+1,j+1)=((N*mi0*I)/(4*pi*(j)))*(((a-i)/sqrt((a-i)^2+j^2))+(i/(sqrt(j^2+i^2))));
end
end
%Rotacija osnovnih dveh matrik za prispevke vseh 4 strani zanke
Bs1=rot90(Bs0,2);
%Rotacija matrike z napacnimi dimenzijami v dimenzije a x b
Bd0=rot90(Bdzacasna);
Bd1=rot90(Bd0,2);
%Sestevanje matrik skupaj
Bsk=(Bs0+Bs1+Bd0+Bd1);
%Brisanje elementov ki so neskonÄŤni
% Bsk(1,:) = [];
% Bsk(a,:) = [];
% Bsk(:,1) = [];
% Bsk(:,b) = [];
%Kopiranje neneskoncnih elementov v novo matriko
%Bvkp=Bsk(2:a,2:b);
%izris
figure;
surf(Bsk);
figure;
%2d barvni prikaz kako se spreminja B glede na polozaj znotraj zanke
contour(Bsk,'DisplayName','Bvkp');figure(gcf)
figure;
%2d barvni prikaz velikosti B
imagesc(Bsk);figure(gcf);
colorbar;
grid on

Teja Muppirala
Teja Muppirala 2011년 6월 6일
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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by