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

조회 수: 37 (최근 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 CenterFile Exchange에서 Animation에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by