以下回答参考 皆我百晓生、券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。
% Set up variables
k = 1/(4*pi*8.85e-12); % Permittivity constant
% Define grid size
dx = 0.5;
dy = 0.5;
% Define domain size
domain_size = 5;
% Define point charges
q = 1; % Charge magnitude
qx = 0; % X location of charge
qy = 0; % Y location of charge
% Calculate coordinates of point charges
x = qx + q * dx;
y = qy + q * dy;
% Calculate positions of vectors R
R = sqrt(x.^2 + y.^2);
R = R / 2; % Normalize R to 1 unit
% Calculate E-field using Gauss' law
E_x = k * q / R;
E_y = k * q / R;
% Plot E-field
quiver(x, y, E_x, E_y, 'Color',[0 0 1], 'LineWidth', 1.5);
xlabel('X');
ylabel('Y');
title('Electric Field of Point Charge');
axis equal;
% Set up variables
k = 1/(4*pi*8.85e-12); % Permittivity constant
% Define grid size
dx = 0.5;
dy = 0.5;
% Define domain size
domain_size = 5;
% Define point charges
q = 1; % Charge magnitude
qx = 0; % X location of charge
qy = 0; % Y location of charge
% Calculate coordinates of point charges
x = qx + q * dx;
y = qy + q * dy;
% Calculate positions of vectors R
R = sqrt(x.^2 + y.^2);
R = R / 2; % Normalize R to 1 unit
% Calculate E-field using Gauss' law
E_x = k * q / R;
E_y = k * q / R;
% Plot E-field
quiver(x, y, E_x, E_y, 'Color',[0 0 1], 'LineWidth', 1.5);
xlabel('X');
ylabel('Y');
title('Electric Field of Point Charge');
axis equal;