필터 지우기
필터 지우기

How to plot a 3D vector field

조회 수: 9 (최근 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 CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by