using quiver function to plot vectors on a hemisphere

2 views (last 30 days)
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 Comments
Star Strider
Star Strider on 29 Nov 2015
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 on 29 Nov 2015
changed the length from 0.5 to 5 and still cannot see any vector arrows :(

Sign in to comment.

Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!