3D vector plot of electric field
144 ビュー (過去 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)
0 件のコメント
回答 (2 件)
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.
0 件のコメント
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Semiconductors and Converters についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!