Plotting dipole field given in polar coordinates
Afficher commentaires plus anciens
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 commentaires
Nolan Canegallo
le 24 Jan 2021
Modifié(e) : Nolan Canegallo
le 24 Jan 2021
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
le 24 Jan 2021
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Cartesian Coordinate System Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

