Chương trình này viết trên Matlab mô phỏng điện trường bao quanh vành tròn tích điện đều. Vector cường độ điện trường biểu diễn trên mạng lưới 3D các điểm trong không gian. Cường độ điện trường được tính toán bằng cách chia nhỏ vành tròn ra thành nhiều đoạn nhỏ, mỗi đoạn có thể xem như một điện tích điểm, tạo ra điện trường theo định luật Coulomb. Tại mỗi vị trí trong không gian, điện trường được tích phân lại theo các “điện trường Coulomb” từ các phần nhỏ ấy.
Kết quả tính toán thể hiện như hình.
Code chương trình
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | function Electric_field_vector_Ring % Author: Tran Hai Cat % Created: 2019.02.02 clc; clear all; close all; %% INPUT DATA Q = 2e-9; % charges R = 0.5; N = 50; streak_arrow = 1; % 1-MUI TEN CONG, 0-MUI TEN THANG xmin = -2; xmax = 2; ymin = -1; ymax = 1; zmin = -1; zmax = 1; %% CALCULATION L = 2*pi*R; lambda = Q/L; dL = L/N; dq = lambda*dL; Nx = 20; Ny = 11; Nz = 11; x = linspace(xmin,xmax,Nx); y = linspace(ymin,ymax,Ny); z = linspace(zmin,zmax,Nz); [X,Y,Z] = meshgrid(x,y,z); ke = 9e9; Ex = zeros(size(X)); Ey = zeros(size(Y)); Ez = zeros(size(Z)); r1 = sqrt(Y.^2+Z.^2); phi = linspace(0,2*pi,N); for iN = 1:N r = sqrt(X.^2+(Y-R*cos(phi(iN))).^2+(Z-R*sin(phi(iN))).^2); E = ke*dq./r./r; Ex = Ex+E./r.*X; % x-component of vector field Ey = Ey+E./r.*(Y-R*cos(phi(iN))); % y-component of vector field Ez = Ez+E./r.*(Z-R*sin(phi(iN))); % z-component of vector field end %% FIGURES figure('name','Electric Field Vector Ring','color','w','numbertitle','off'); if streak_arrow streakarrow3d(X,Y,Z,Ex,Ey,Ez,2,1); else quiver3(X,Y,Z,Ex,Ey,Ez,'AutoScaleFactor',3); end hold on % Draw the ring: x1 = zeros(size(phi)); y1 = R*cos(phi); z1 = R*sin(phi); plot3(x1,y1,z1,'linewidth',3); %% Axis properties axis equal axis([xmin xmax ymin ymax zmin zmax]); rotate3d on xlabel('X, m'); ylabel('Y, m'); zlabel('Z, m'); view(-20,30); box on grid off set(gca,'color','w') function hh=streakarrow3d(X,Y,Z,U,V,W,np,AC) %% Bertrand Dano 03-09 % Copyright 1984-2009 The MathWorks, Inc. DX=abs(X(1,1,1)-X(1,2,1)); DY=abs(Y(1,1,1)-Y(2,1,1)); DZ=abs(Z(1,1,1)-Z(1,1,2)); DD=min([DX DY DZ]); ks=DD/100; % Size of the "dot" for the tuft graphs np=np*10; alpha = 3; % Size of arrow head relative to the length of the vector beta = .15; % Width of the base of the arrow head relative to the length XYZ=stream3(X,Y,Z,U,V,W,X,Y,Z); Vmag=sqrt(U.^2+V.^2+W.^2); Vmin=min(Vmag(:));Vmax=max(Vmag(:)); Vmag=Vmag(:); cmap=colormap; for k=1:length(XYZ) F=XYZ(k); [L M]=size(F{1}); if L<np F0{1}=F{1}(1:L,:); if L==1 F1{1}=F{1}(L,:); else F1{1}=F{1}(L-1:L,:); end else F0{1}=F{1}(1:np,:); F1{1}=F{1}(np-1:np,:); end P=F1{1}; if AC==1 vcol=floor((Vmag(k)-Vmin)./(Vmax-Vmin)*64); if vcol==0; vcol=1; end COL=[cmap(vcol,1) cmap(vcol,2) cmap(vcol,3)]; else COL='k'; end hh=streamline(F0); set(hh,'color',COL,'linewidth',.5); if L>1 x1=P(1,1); y1=P(1,2); z1=P(1,3); x2=P(2,1); y2=P(2,2); z2=P(2,3); u=x2-x1; v=y2-y1; w=z2-z1; uv=sqrt(u.*u + v.*v); xa1=x2+u-alpha*(u+beta*(v+eps)); xa2=x2+u-alpha*(u-beta*(v+eps)); xa3=x2+u-alpha*u; ya1=y2+v-alpha*(v-beta.*(u+eps)); ya2=y2+v-alpha*(v+beta.*(u+eps)); ya3=y2+v-alpha*v; za1=z2+w-alpha*w; za2=z2+w-alpha*(w+beta.*(uv+eps)); za3=z2+w-alpha*(w-beta.*(uv+eps)); plot3([x2 xa1 xa2 x2 xa3 xa3 x2],[y2 ya1 ya2 y2 ya3 ya3 y2],[z2 za1 za1 z2 za2 za3 z2],'color',COL); hold on end end axis image |