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.
How to plot a 3D vector field
8 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
Ege Keskin
2019-2-3
3 个评论
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
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Vector Fields 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!