using quiver function to plot vectors on a hemisphere

1 次查看(过去 30 天)
Hi, I'm trying to plot the magnetic field on the surface of a hemisphere (modelling a planetary dipole).
I have created a function magfield2 that produces the direction and magnitude of the magnetic field at some point (X,Y,Z) on the surface of a hemisphere, shown here:
if true
function [U,V,W] = magfield2(X,Y,Z) %U=mag force in X, V=mag force in Y, W=mag force in Z
r=(X.^2+Y.^2+Z.^2)^0.5 ;
U=3*X.*Z./(r.^5);
V=3*X.*Z./(r.^5);
W=((3*Z.^2 - r.^2)/r.^5);
% code
end
I then try to use this function with the quiver function to plot this magnetic field at the surface as shown here
if true
[X,Y,Z] = sphere(50); %defines meshgrid coverage
[U,V,W] = magfield2(X,Y,Z); %magnetic field function
figure
quiver3(X,Y,Z,U,V,W,0.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
view(-35,45)%canges initial viewing angle
axis([0 3 -1.5 1.5 -1.5 1.5]) %defines axis parameters
hold off
% code
end
Sadly, this just produces a hemisphere surface with no vectors on it. If I swap the magfield2 function with a surface normal function it seems to work fine.
Any comments/ suggestions would be appreciated. Thanks, John!
  2 个评论
Star Strider
Star Strider 2015-11-29
The arrows plot (it seems to me correctly), but it’s difficult to see them because you scaled them to be short. Lengthen them to see them.
John Draper
John Draper 2015-11-29
changed the length from 0.5 to 5 and still cannot see any vector arrows :(

请先登录,再进行评论。

回答(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