3D vector plot of electric field

조회 수: 140 (최근 30일)
Quant.Phys42
Quant.Phys42 2020년 1월 30일
편집: David Goodmanson 2020년 1월 30일
I'm having some issues with 3D vector plotting an electric field assoicated with a charge over some range (picture attached)
This is what i have thus far:
x=linspace(0,2,10);
y=linspace(0,2,10);
z=linspace(0,2,10);
[XX,YY,ZZ]=meshgrid(x,y,z)
Q=1.e-9
C=9.e9
r=(x.^2+y.^2+z.^2).^.5
Ex=Q*C/r.^3*x
Ey=Q*C/r.^3*y
Ez=Q*C/r.^3*z
figure()
quiver3(x,y,z,Ex,Ey,Ez)
view(-35,45)

답변 (2개)

David Goodmanson
David Goodmanson 2020년 1월 30일
편집: David Goodmanson 2020년 1월 30일
Hello QP,
Once you have made the matrix variables XX,YY,ZZ, those are the ones you use for further calculation, no longer x,y,z. (Notationally, you could create the matrices with names x,y,z so as to not have to use the more cumbersome XX etc. further on down). In addition, you have not made use of the position of the charge. It's the displacements from the charge location that matter. Displacements in the x direction are XX-x0, etc. All of this becomes
x0 = 1;
y0 = 1;
z0 = 4;
r=((XX-x0).^2+(YY-y0).^2+(ZZ-z0).^2).^.5;
Ex = Q*C*(XX-x0)./r.^3;
etc.
quiver3(XX,YY,ZZ,Ex,Ey,Ez)
Several times ./ and .* are required, for element-by-element multiplication of variables.

KSSV
KSSV 2020년 1월 30일
편집: KSSV 2020년 1월 30일
m = 10 ; n = 10 ; p = 10 ;
x=linspace(0,2,m);
y=linspace(0,2,n);
z=linspace(0,2,p);
[x,y,z]=meshgrid(x,y,z) ;
Q=1.e-9 ;
C=9.e9 ;
r=(x.^2+y.^2+z.^2).^.5;
Ex = Q*C./r.^3.*x ;
Ey = Q*C./r.^3.*y ;
Ez = Q*C./r.^3.*z ;
figure()
hold on
for i = 1:p
quiver3(x(:,:,i),y(:,:,i),z(:,:,i),Ex(:,:,i),Ey(:,:,i),Ez(:,:,i))
end
view(-35,45)
Without loop, you can also draw in a single stretch using:
quiver3(x(:),y(:),z(:),Ex(:),Ey(:),Ez(:),3)
When you use the above one, you need to specify the scaling factor and size of the arrows.

카테고리

Help CenterFile Exchange에서 Semiconductors and Converters에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by