How to plot a 3D vector field

4 ビュー (過去 30 日間)
Ege Keskin
Ege Keskin 2019 年 1 月 31 日
コメント済み: prachi jain 2019 年 6 月 20 日
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)

採用された回答

Ege Keskin
Ege Keskin 2019 年 2 月 3 日
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 件のコメント
Ege Keskin
Ege Keskin 2019 年 3 月 15 日
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 2019 年 6 月 20 日
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

サインインしてコメントする。

その他の回答 (2 件)

KSSV
KSSV 2019 年 1 月 31 日
YOu need to define the values of (x,y,z) sibstiutue these values in Bx, By Bz using subs and then use quiver3.
  3 件のコメント
KSSV
KSSV 2019 年 1 月 31 日
read about _ndgrid_
KSSV
KSSV 2019 年 1 月 31 日
my suggestion..you need not to use syms.

サインインしてコメントする。


Ege Keskin
Ege Keskin 2019 年 2 月 1 日
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.

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by