Hello. I am trying to plot the magnetic flux density of a permanent magnet around its viscinity. the magnetic flux density at any point in space (x,y,z) has 3 components, Bx,By and Bz, where all of them are functions of x,y and z. My duty is to plot these vector fields. I have the equations written down but I couldn't gain any progress on plotting. In the end, the vector field should look like the iconic magnetic field lines of a magnet. Here is the code and the equations. Thanks for your help.
syms x y z
a = 1; %dimensions of the permanent magnet
b = 1;
c = 0.5;
Nu0 = 1.25e-6; %(m.kg)/(s^2.A^2) permeability of free space
M = 1; %tesla
F_1xyz = atan(((x+a)*(y+b)) / ((z+c)*sqrt((x+a)^2+(y+b)^2+(z+c)^2))); %F1(x,y,z)
F_1xxyz = atan(((-x+a)*(y+b)) / ((z+c)*sqrt((-x+a)^2+(y+b)^2+(z+c)^2))); %F1(-x,y,z)
F_1xxyzz = atan(((-x+a)*(y+b)) / ((-z+c)*sqrt((-x+a)^2+(y+b)^2+(-z+c)^2))); %F1(-x,y,-z)
F_1xxyyz = atan(((-x+a)*(-y+b)) / ((z+c)*sqrt((-x+a)^2+(-y+b)^2+(z+c)^2))); %F1(-x,-y,z)
F_1xxyyzz = atan(((-x+a)*(-y+b)) / ((-z+c)*sqrt((-x+a)^2+(-y+b)^2+(-z+c)^2))); %F1(-x,-y,-z)
F_1xyzz = atan(((x+a)*(y+b)) / ((-z+c)*sqrt((x+a)^2+(y+b)^2+(-z+c)^2))); %F1(x,y,-z)
F_1xyyz = atan(((x+a)*(-y+b)) / ((z+c)*sqrt((x+a)^2+(-y+b)^2+(z+c)^2))); %F1(x,-y,z)
F_1xyyzz = atan(((x+a)*(-y+b)) / ((-z+c)*sqrt((x+a)^2+(-y+b)^2+(-z+c)^2))); %F1(x,-y,-z)
F_2xyz = (sqrt((x+a)^2+(y-b)^2+(z+c)^2)+b-y) / (sqrt((x+a)^2+(y+b)^2+(z+c)^2)-b-y); %F2(x,y,z)
F_2xxyzz = (sqrt((-x+a)^2+(y-b)^2+(-z+c)^2)+b-y) / (sqrt((-x+a)^2+(y+b)^2+(-z+c)^2)-b-y);%F2(-x,y,-z)
F_2xyzz = (sqrt((x+a)^2+(y-b)^2+(-z+c)^2)+b-y) / (sqrt((x+a)^2+(y+b)^2+(-z+c)^2)-b-y); %F2(x,y,-z)
F_2xxyz = (sqrt((-x+a)^2+(y-b)^2+(z+c)^2)+b-y) / (sqrt((-x+a)^2+(y+b)^2+(z+c)^2)-b-y); %F2(-x,y,z)
F_2yyxzz = (sqrt((-y+a)^2+(x-b)^2+(-z+c)^2)+b-x) / (sqrt((-y+a)^2+(x+b)^2+(-z+c)^2)-b-x); %F2(-y,x,-z)
F_2yxz = (sqrt((y+a)^2+(x-b)^2+(z+c)^2)+b-x) / (sqrt((y+a)^2+(x+b)^2+(z+c)^2)-b-x); %F2(y,x,z)
F_2yxzz = (sqrt((y+a)^2+(x-b)^2+(-z+c)^2)+b-x) / (sqrt((y+a)^2+(x+b)^2+(-z+c)^2)-b-x); %F2(y,x,-z)
F_2yyxz = (sqrt((-y+a)^2+(x-b)^2+(z+c)^2)+b-x) / (sqrt((-y+a)^2+(x+b)^2+(z+c)^2)-b-x); %F2(-y,x,z)
Bx = ((Nu0*M)/(4*pi))*log((F_2xxyzz*F_2xyz)/(F_2xyzz*F_2xxyz)); %x component of the magnetic flux density vector at point (x,y,z)
By = ((Nu0*M)/(4*pi))*log((F_2yyxzz*F_2yxz)/(F_2yxzz*F_2yyxz)); %y component of the magnetic flux density vector at point (x,y,z)
Bz = -((Nu0*M)/(4*pi))*(F_1xxyz + F_1xxyzz + F_1xxyyz + F_1xxyyzz + F_1xyz + F_1xyzz + F_1xyyz + F_1xyyzz ); %z component of the magnetic flux density vector at point (x,y,z)

 Akzeptierte Antwort

Ege Keskin
Ege Keskin am 3 Feb. 2019

1 Stimme

UPDATE: I have found a user made function that takes a 3d matrix and visualizes it. Which solved my problem instantly. The function is vis3d if anyone wants to take glimpse.

3 Kommentare

Kenneth A. Meyerson
Kenneth A. Meyerson am 15 Mär. 2019
Hello Ege,
I am also interested in simulating the magnetic flux density of a permanent magnet and was wondering if you would be open to sharing your implementation that uses vis3d. I am planning to evalute two independent magnets and, through superposition, identify the flux density along a path defined in cartesian coodinates. This basically helps reduce the guesswork invovled with identifying the magnet strength needed to for a hall effect sensor.
- K
Ege Keskin
Ege Keskin am 15 Mär. 2019
Hello Kenneth,
Unfortunately, I cannot share my code with you since it is included in my Masters thesis. However, I can share with you the end results. This is the plot of the magnetic flux density lines of a rectangular neodymium magnet.
-Best regards..
prachi jain
prachi jain am 20 Jun. 2019
Hello Kenneth,
Did you find the answer to your question?
I am doing a similar thing for my research. Please share if you were successful.
-Prachi

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

KSSV
KSSV am 31 Jan. 2019

0 Stimmen

YOu need to define the values of (x,y,z) sibstiutue these values in Bx, By Bz using subs and then use quiver3.

3 Kommentare

Ege Keskin
Ege Keskin am 31 Jan. 2019
and how can I do this for all of the points in a 10x10x10 space with 0.1 intervals?
KSSV
KSSV am 31 Jan. 2019
read about _ndgrid_
KSSV
KSSV am 31 Jan. 2019
my suggestion..you need not to use syms.

Melden Sie sich an, um zu kommentieren.

Ege Keskin
Ege Keskin am 1 Feb. 2019

0 Stimmen

I still do not have my answer. All of the examples and sketches on the internet have 2 variables. for example z = x*y. However in my case, I am dealing with functions such as Bx = x*y*z So the functions like quiver3 does not work with for me. I need something to evaluate any point in space according to three formulas which are all dependant on 3 variables x,y,z.

Produkte

Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by