필터 지우기
필터 지우기

quiver3 using 3D spherical coordinates?

조회 수: 6 (최근 30일)
John Draper
John Draper 2016년 1월 5일
댓글: Bin Jiang 2023년 3월 2일
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