How can I show Electric Potential due to a Dipole as a 3D surface?

35 ビュー (過去 30 日間)
Luca
Luca 2022 年 8 月 26 日
回答済み: David Goodmanson 2022 年 8 月 27 日
Hi,
I'm very new to matlab and have been picking my brain over how to 3D plot the electric potetial due to a dipole.
Here is the code I have currently come up with:
---------------
clear;clf
[X,Y] = meshgrid(-2: .4: 2, -2: .4: 2)
r = sqrt(X.^2+Y.^2)
Z = (1/2)*1./(r.^2)
surf(X,Y,Z)
--------------
Where Z represents the Electric Potential scalar field. NOTE: I have purposely excluded cos(theta) in the numerator for simplicity (and because I cannot seem to successfully include it). I kind of have a few questions:
  • How do I avoid from dividing by 0? (This leaves a gap in the tip of the plot)
  • How can I successfully include the cosine argument ( since it is necessary to provide an accurate plot)
I would really appreciate some help.
  2 件のコメント
KSSV
KSSV 2022 年 8 月 26 日
Where you want to include the cosine argumnet?
Luca
Luca 2022 年 8 月 27 日
It needs to be in the numerator of Z

サインインしてコメントする。

回答 (1 件)

David Goodmanson
David Goodmanson 2022 年 8 月 27 日
Hi Luca,
Since you can't show the values of the potential at every point in the 3d space, this is most commonly done by showing a surface of constant potential. The following code first plots a sphere of radius 1 as a demo, with x,y,z defined by the usual two angles in spherical coordinates
Ignoring some constants, the potential is phi = cos(theta)/r^2. Suppose phi = +1 is the constant value. then r = sqrt(cos(theta)). In the upper hemisphere cos(theta) is positive so the sqare root works. In the lower hemisphere cos(theta) is negative, so in order to plot that, one can use r = sqrt(abs(cos(theta))) which works, at the cost of the potential coming out at a constant -1 in the lower hemisphere, which is actually physically correct. (If you only want the upper lobe then th1 below can be given an upper limit of pi/2).
th1 = linspace(0,pi,31);
phi1 = linspace(0,2*pi,41);
[th phi] = meshgrid(th1,phi1);
R = 1; % sphere
% R = sqrt(abs(cos(th))); % uncomment this line for the dipole
x = R.*sin(th).*cos(phi);
y = R.*sin(th).*sin(phi);
z = R.*cos(th);
surf(x,y,z)
axis equal

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by