"""\n% 设置常量\nk = 9 * 10^9; % 电场常量\nQ = 1; % 电荷量\nL = 1; % 电荷间距\nx = -5:0.1:5; % x轴范围\n\n% 计算电场\nEx1 = k * Q ./ (x + L).^2 - k * Q ./ (x - L).^2; % x轴方向上的电场\nEy1 = zeros(size(x)); % y轴方向上的电场\n\nEx2 = k * Q ./ (x + L).^2 + k * Q ./ (x - L).^2; % x轴方向上的电场\nEy2 = zeros(size(x)); % y轴方向上的电场\n\n% 绘制电场图形\nfigure;\nhold on;\nplot(x, Ex1, 'r-', 'LineWidth', 2); % 在轴线的延长线上的电场\nplot(x, Ey1, 'b--', 'LineWidth', 2); % 在中垂线上的电场\nplot(x, Ex2, 'g-', 'LineWidth', 2); % 在轴线的延长线上的电场\nplot(x, Ey2, 'm--', 'LineWidth', 2); % 在中垂线上的电场\nxlabel('x');\nylabel('Electric Field');\nlegend('Electric Field on Extension of Axis', 'Electric Field on Perpendicular Bisector', 'Electric Field on Extension of Axis', 'Electric Field on Perpendicular Bisector');\ntitle('Electric Field of Equal and Opposite Charges');\ngrid on;\nhold off;\n"""\n运行上述代码,即可得到等量异号点电荷在轴线的延长线上和中垂线上的电场图形。

MATLAB绘制等量异号点电荷电场分布图

原文地址: https://www.cveoy.top/t/topic/pGJX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录