using quiver function to plot vectors on a hemisphere

조회 수: 2 (최근 30일)
John Draper
John Draper 2015년 11월 29일
댓글: John Draper 2015년 11월 29일
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