Plotting dipole field given in polar coordinates
이전 댓글 표시
Hello, I'm trying to plot a dipole field around a uniformly polarized sphere.
Here is the setup where u is supposed to represent the field component in r-hat direction and v represents the vector component in theta-hat direction.
[x,y] = meshgrid(-8:0.5:8,-8:0.5:8);
%% for base change
r = sqrt(x.^2 + y.^2); % r in function of (x, y)
theta = atan2(y, x); % theta in function of (x, y)
%% Constants
rad = 2; %radius of sphere
pre = 0.1; %pre factor
scale1=50; %scaling factors for better visibility
scale2=200;
%% Definition of vectors in polar coordinates:
u = ((2*pre)./(r.*r.*r)).*cos(theta); %r-hat
v = (pre./(r.*r.*r)).*sin(theta); %theta-hat
afterwards i go over to plotting the vectors using the quiver function.
I'm not really sure if u*cos(theta) and v*sin(theta) are the right steps here. Basically, I want to plot the vector field given in polar coordinates in cartesian coordinates and I don't know if my transformation steps are correct.
%% plotter
figure(1)
hold on;
for i=1:33
for n=1:33
if((sqrt(x(i,n)*x(i,n)+y(i,n)*y(i,n)))>rad*2)
quiver(x(i,n), y(i,n), u(i,n)*cos(theta(i,n)), v(i,n)*sin(theta(i,n)),scale2,'r')
hold on;
elseif ((sqrt(x(i,n)*x(i,n)+y(i,n)*y(i,n)))>rad)
quiver(x(i,n), y(i,n), u(i,n)*cos(theta(i,n)), v(i,n)*sin(theta(i,n)),scale1,'r')
hold on;
end
end
end
I'm fairly new to matlab so your help is greatly appreciated.
Thank You :)
댓글 수: 2
Nolan Canegallo
2021년 1월 24일
편집: Nolan Canegallo
2021년 1월 24일
I have a few questions in order to verify my solution.
- Where are the poles located on your sphere/circle?
- What are the base/original equations that you are using?
Philipp Traxler
2021년 1월 24일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Cartesian Coordinate System Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

