- #1
jadelsky
- 13
- 0
% varibles
% I current(A) in +phi direction on ring
% a ring radius (m)
% Ndeg number of increments for phi
% f angle of phi in radians
% df differential change in phi
% dL differential length vector on the ring
% dLmag magnitude of dL
% dLuv unit vector in direction of dL
% [xL,yL,0] location of source point
% Ntest number of test points
% Rsuv unit vector from origin to source point
% R vector from source to test point
% Ruv unit vector for R
% Rmag magnitude of R
% dH differential portion of H
% dHmag magnitude pf dH
% radius radial distance from origin
% Hz total magnetic field at test point
clc
clear
% initialize variables
a=1;
I=1;
Ndeg=90;
Ntest=40;
df=360/Ndeg;
dLmag=(df*pi/180)*a;
% perform calculation
for j=1:Ntest
x=(j-1)*a/Ntest;
for i=1:df:360
f=i*pi/180;
xL=a*cos(f);
yL=a*sin(f);
Rsuv=[xL yL 0]/a;
dLuv=cross([0 0 1],Rsuv);
dL=dLmag*dLuv;
R=[x-xL -yL 0];
Rmag=magvector(R);
Ruv=R/Rmag;
dH=I*cross(dL,Ruv)/(4*pi*Rmag^2);
dHmag(i)=magvector(dH);
end
radius(j)=x;
Hz(j)=sum(dHmag);
end
% generate plot
plot(radius,Hz)
grid on
xlabel('radius(m)')
ylabel('Hz(A/m)')
well this shoul calculate the magnetic field of current loop, but i get this error:
? Undefined function or method 'magvector' for input arguments of type
'double'.
Error in ==> test at 43
Rmag=magvector(R);
how can i solve this anyone?
% I current(A) in +phi direction on ring
% a ring radius (m)
% Ndeg number of increments for phi
% f angle of phi in radians
% df differential change in phi
% dL differential length vector on the ring
% dLmag magnitude of dL
% dLuv unit vector in direction of dL
% [xL,yL,0] location of source point
% Ntest number of test points
% Rsuv unit vector from origin to source point
% R vector from source to test point
% Ruv unit vector for R
% Rmag magnitude of R
% dH differential portion of H
% dHmag magnitude pf dH
% radius radial distance from origin
% Hz total magnetic field at test point
clc
clear
% initialize variables
a=1;
I=1;
Ndeg=90;
Ntest=40;
df=360/Ndeg;
dLmag=(df*pi/180)*a;
% perform calculation
for j=1:Ntest
x=(j-1)*a/Ntest;
for i=1:df:360
f=i*pi/180;
xL=a*cos(f);
yL=a*sin(f);
Rsuv=[xL yL 0]/a;
dLuv=cross([0 0 1],Rsuv);
dL=dLmag*dLuv;
R=[x-xL -yL 0];
Rmag=magvector(R);
Ruv=R/Rmag;
dH=I*cross(dL,Ruv)/(4*pi*Rmag^2);
dHmag(i)=magvector(dH);
end
radius(j)=x;
Hz(j)=sum(dHmag);
end
% generate plot
plot(radius,Hz)
grid on
xlabel('radius(m)')
ylabel('Hz(A/m)')
well this shoul calculate the magnetic field of current loop, but i get this error:
? Undefined function or method 'magvector' for input arguments of type
'double'.
Error in ==> test at 43
Rmag=magvector(R);
how can i solve this anyone?