Demo entry 6789439

try

   

Submitted by Jane on Apr 29, 2019 at 08:49
Language: Matlab. Code size: 1.9 kB.

clear
clc
%%
% Set charge density p, electrostatic constant k
p=1e-9;
k=9e9;
% Set the range of the field in x direction and y direction
xm=4;
ym=4;
% Evenly divide the x axis and y axis vinto n segments
n=200;
x=linspace(-xm,xm,n);
y=linspace(-ym,ym,n);
% To form the coordinates of each point in the field
[X,Y]=meshgrid(x,y);
% Calculate the distribution of electric potential at each point of the coordinate by using integration method
s=1-X+sqrt((1-X).^2+Y.^2);
t=-1-X+sqrt((1+X).^2+Y.^2);
V=k*p*log(s./t);

% Plot the distribution of electric potential
figure(1)
mesh(X,Y,V);
grid on
hold on;
title('Potential distribution of line charge in vacuum-Integration method','fontsize',12);
xlabel('X axis(unit:m)','fontsize',12);
ylabel('Y axis(unit:m)','fontsize',12);

%%
% Get the minimum and the maximum potential value for a family of equipotential lines
Vmin=0;
Vmax=2000;
% Set the potential for equipotential lines
Veq=linspace(Vmin,Vmax,2000);

% Plot equipotential lines
figure(2)
contour(X,Y,V,Veq);
grid on;
hold on;
title({'Isopotential Line of line charge Electric Field in vacuum','杨媛 11712841'}, 'fontsize', 12);
xlabel('X axis(unit:m)','fontsize',12);
ylabel('Y axis(unit:m)','fontsize',12);
axis equal

%%
% Calculation of two components of Electric Field intensity at each Point in the Field
[Ex,Ey]=gradient(-V);
% Generate the x and y coordinate for the start of the field line;
dx=0.05;
nx=-1:dx:1;
xs = [-1:0.05:1,1:-0.05:-1];
ys = [0.01*ones(1,41),-0.01*ones(1,41)];

% Plot electric field line
figure(3)
streamline(X,Y,Ex,Ey,xs,ys);
grid on;
hold on;
contour(X,Y,V,Veq);
title({'Isopotential Line and Power Line of line charge Electric Field in vacuum (expressed by smooth continuous Curves)','杨媛 11712841'},'fontsize',12);
xlabel('X axis(unit: m)', 'fontsize', 12);
ylabel('Y axis(unit: m)', 'fontsize', 12);
axis equal

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).