quiver3 using 3D spherical coordinates?

5 次查看(过去 30 天)
Hi, I've read a lot of posts on this site about using quiver3 to plot a function in non-rectangular coordinates and I am still a little bit confused.
Here is my attempt to plot a 3D function in spherical coordinates using quiver3
if true
[r,theta,phi] = meshgrid(0:0.1:100,-pi/2:pi/100:pi/2, 0:pi/100:pi); %defines meshgrid coverage
%r=(X.^2+Y.^2+Z.^2).^0.5 ;
const=1; %mu_0 * M_4 / 4*pi
Br= const*2*cos(theta)./(r.^3); %mag field in rho
Btheta= const*sin(theta)./(r.^3);%mag field in theta
Bphi=0;
%magnetic field function
figure
quiver3(r,theta,phi,Br,Btheta,Bphi,5)% no defines arrow length, other define direction
%defines arrow direction (u,v,w) at point (x,y,z)
hold on
%surf(X,Y,Z) %produces surface
axis equal %defines axis parameters
hold off
% code
end
This didn't seem to work (I got an error saying V and W need to be the same size). So I tried converting to rectangular before using the quiver function.
if true
[r,theta,phi] = meshgrid(0:0.1:100,-pi/2:pi/100:pi/2, 0:pi/100:pi); %defines meshgrid coverage
%r=(X.^2+Y.^2+Z.^2).^0.5 ;
const=1; %mu_0 * M_4 / 4*pi
U= const*2*cos(theta)./(r.^3); %mag field in rho
V= const*sin(theta)./(r.^3);%mag field in theta
W=0;
%magnetic field function
r=(X.^2+Y.^2+Z.^2).^0.5 ;
X=r.*sin(phi).*cos(theta);
Y=r.*sin(phi).*sin(theta);
Z=r.*cos(phi);
figure
quiver3(X,Y,Z,U,V,W,5)% no defines arrow length, other define direction
%defines arrow direction (u,v,w) at point (x,y,z)
hold on
%surf(X,Y,Z) %produces surface
axis equal %defines axis parameters
hold off
% code
end
Which doesn't seem to work either. Is it not possible to use spherical coordinate in quiver or am I doing something wrong?
Thanks, John
  2 个评论
John Draper
John Draper 2016-1-5
After doing some more reading, I think I realise the answer to my question is no. It is better to convert back into Cartesian and then use the quiver3 function.
Bin Jiang
Bin Jiang 2023-3-2
It seems that you only specified one element to W, while it should be something like sz=size(U); W= zeros(sz). Perhaps, there is a better way!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by