INTRODUCTION TO ELECTROMAGENTIC FIELDS
EXPERIMENT # 3
ELECTRIC FIELD INTENSITY
Objective:
Introduction to Electric Field Intensity.
To find E-field around point charge, line charge and surface charge.
Verifying the results using MatLab code
Equipment Required:
Computer having MATLAB software
Introduction:
ELECTRIC FIELD INTENSITY
We define the electric field intensity as the vector of force on a unit positive test charge. Electric field
intensity, E, is measured by the unit newtons per
coulomb (N/C) or volts per meter (V/m). The electric field intensity E at any point in space due to a
charge Q is given by:
Or In vector form
where:
E is the electric field intensity.
Q is the charge.
ε0 is the permittivity of free space.
r is the distance from the charge.
aR is a unit vector in the direction from the point at which the point
charge Q is located, to the point at which E is desired/measured
MATLAB CODE
Task 1) Electric Field around positive charge
% Constants
Q = 1e-9; % Positive charge in Coulombs (1 nC)
epsilon_0 = 8.854e-12; % Permittivity of free space (F/m)
% Create a grid of points in 3D space
[x, y, z] = meshgrid(-2:0.5:2, -2:0.5:2, -2:0.5:2); % Adjusted for better arrow visibility
% Calculate the distance of each point from the origin (positive charge location)
r = sqrt(x.^2 + y.^2 + z.^2);
r(r == 0) = eps; % Avoid division by zero at the origin
% Electric field intensity magnitude for positive charge
E_magnitude = (Q ./ (4 * pi * epsilon_0 * r.^2));
% Calculate the components of the electric field in x, y, and z directions
Ex = E_magnitude .* (x ./ r);
Ey = E_magnitude .* (y ./ r);
Ez = E_magnitude .* (z ./ r);
% Create a figure
figure;
hold on;
% Plot the electric field vectors using quiver3
quiver3(x(1:3:end, 1:3:end, 1:3:end), ...
y(1:3:end, 1:3:end, 1:3:end), ...
z(1:3:end, 1:3:end, 1:3:end), ...
Ex(1:3:end, 1:3:end, 1:3:end), ...
Ey(1:3:end, 1:3:end, 1:3:end), ...
Ez(1:3:end, 1:3:end, 1:3:end), ...
'b', 'AutoScale', 'on', 'LineWidth', 1.5); % Electric field vectors
% Plot the positive charge as a filled circle
plot3(0, 0, 0, 'ro', 'MarkerFaceColor', 'r', 'MarkerSize', 10); % Positive charge
% Set labels and title
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Electric Field Vectors from a Positive Charge');
% Create a legend
legend('Electric Field Vectors', 'Positive Charge (1 nC)', 'Location', 'Best');
grid on;
axis equal;
hold off;
Task 2) negative charge
% Constants
Q = -1e-6; % Negative charge in Coulombs (-1 µC)
epsilon_0 = 8.854e-12; % Permittivity of free space (F/m)
% Create a grid of points in 3D space
[x, y, z] = meshgrid(-2:0.5:2, -2:0.5:2, -2:0.5:2); % Adjusted for better arrow visibility
% Calculate the distance of each point from the origin (negative charge location)
r = sqrt(x.^2 + y.^2 + z.^2);
r(r == 0) = eps; % Avoid division by zero at the origin
% Electric field intensity magnitude for negative charge
E_magnitude = (Q ./ (4 * pi * epsilon_0 * r.^2));
% Calculate the components of the electric field in x, y, and z directions
Ex = E_magnitude .* (x ./ r);
Ey = E_magnitude .* (y ./ r);
Ez = E_magnitude .* (z ./ r);
% Create a figure
figure;
hold on;
% Plot the electric field vectors using quiver3
quiver3(x(1:3:end, 1:3:end, 1:3:end), ...
y(1:3:end, 1:3:end, 1:3:end), ...
z(1:3:end, 1:3:end, 1:3:end), ...
Ex(1:3:end, 1:3:end, 1:3:end), ...
Ey(1:3:end, 1:3:end, 1:3:end), ...
Ez(1:3:end, 1:3:end, 1:3:end), ...
'b', 'AutoScale', 'on', 'LineWidth', 1.5); % Electric field vectors
% Plot the negative charge as a filled circle
plot3(0, 0, 0, 'bo', 'MarkerFaceColor', 'b', 'MarkerSize', 10); % Negative charge
% Set labels and title
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Electric Field Vectors from a Negative Charge');
% Create a legend
legend('Electric Field Vectors', 'Negative Charge (-1 µC)', 'Location', 'Best');
grid on;
axis equal;
hold off;
Task 3 ) E-Field for both a positive charge and a negative charge:
% Constants
Q_pos = 1e-9; % Positive charge in Coulombs (1 nC)
Q_neg = -1e-9; % Negative charge in Coulombs (-1 nC)
epsilon_0 = 8.854e-12; % Permittivity of free space (F/m)
% Create a grid of points in 3D space
[x, y, z] = meshgrid(-3:0.5:3, -3:0.5:3, -3:0.5:3); % Adjusted for better arrow visibility
% Calculate distances from each charge location
r_pos = sqrt((x - 1).^2 + (y - 1).^2 + (z - 1).^2); % Distance from positive charge at (1,1,1)
r_neg = sqrt((x + 1).^2 + (y + 1).^2 + (z + 1).^2); % Distance from negative charge at (-1,-1,-1)
% Avoid division by zero
r_pos(r_pos == 0) = eps;
r_neg(r_neg == 0) = eps;
% Electric field intensity magnitudes for both charges
E_magnitude_pos = (Q_pos ./ (4 * pi * epsilon_0 * r_pos.^2));
E_magnitude_neg = (Q_neg ./ (4 * pi * epsilon_0 * r_neg.^2));
% Calculate electric field components in x, y, and z directions
Ex_pos = E_magnitude_pos .* ((x - 1) ./ r_pos);
Ey_pos = E_magnitude_pos .* ((y - 1) ./ r_pos);
Ez_pos = E_magnitude_pos .* ((z - 1) ./ r_pos);
Ex_neg = E_magnitude_neg .* ((x + 1) ./ r_neg);
Ey_neg = E_magnitude_neg .* ((y + 1) ./ r_neg);
Ez_neg = E_magnitude_neg .* ((z + 1) ./ r_neg);
% Total electric field components
Ex = Ex_pos + Ex_neg;
Ey = Ey_pos + Ey_neg;
Ez = Ez_pos + Ez_neg;
% Create a figure
figure;
hold on;
% Plot the electric field vectors using quiver3
quiver3(x(1:3:end, 1:3:end, 1:3:end), ...
y(1:3:end, 1:3:end, 1:3:end), ...
z(1:3:end, 1:3:end, 1:3:end), ...
Ex(1:3:end, 1:3:end, 1:3:end), ...
Ey(1:3:end, 1:3:end, 1:3:end), ...
Ez(1:3:end, 1:3:end, 1:3:end), ...
'b', 'AutoScale', 'on', 'LineWidth', 1.5); % Electric field vectors
% Plot the positive charge as a filled circle
plot3(1, 1, 1, 'ro', 'MarkerFaceColor', 'r', 'MarkerSize', 10); % Positive charge
% Plot the negative charge as a filled circle
plot3(-1, -1, -1, 'bo', 'MarkerFaceColor', 'b', 'MarkerSize', 10); % Negative charge
% Set labels and title
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Electric Field Vectors from Multiple Charges');
% Create a legend
legend('Electric Field Vectors', 'Positive Charge (1 nC)', 'Negative Charge (-1 nC)', 'Location',
'Best');
grid on;
axis equal;
hold off;
Task 4) Visualizing force in the context of electric fields can be accomplished by
representing how charges experience forces due to electric fields produced by other
charges. Here’s how to visualize force in the context of electric fields in MATLAB
Steps to Visualize Force
1. Define the Charges: Set the positions and magnitudes of the positive and negative charges.
2. Calculate Electric Field: Compute the electric field created by these charges.
3. Calculate Forces on Charges: For a test charge placed in the electric field, calculate the force
experienced by this charge due to the electric field.
4. Visualize Forces: Use arrows to represent the force vectors acting on the test charge
Example MATLAB Code
Below is an example MATLAB code that visualizes the force acting on a test charge due to a
positive and a negative charge:
% Constants
Q_pos = 1e-9; % Positive charge in Coulombs (1 nC)
Q_neg = -1e-9; % Negative charge in Coulombs (-1 nC)
epsilon_0 = 8.854e-12; % Permittivity of free space (F/m)
% Positions of the charges
pos_charge = [1, 1, 1]; % Positive charge location
neg_charge = [-1, -1, -1]; % Negative charge location
test_charge = [0, 0, 0]; % Test charge location at the origin
% Create a grid of points in 3D space
[x, y, z] = meshgrid(-3:0.5:3, -3:0.5:3, -3:0.5:3); % Adjusted for better visibility
%% Effect of Positive Charge
% Calculate distances from the positive charge location
r_pos = sqrt((x - pos_charge(1)).^2 + (y - pos_charge(2)).^2 + (z - pos_charge(3)).^2);
% Avoid division by zero
r_pos(r_pos == 0) = eps;
% Electric field intensity magnitude for the positive charge
E_magnitude_pos = (Q_pos ./ (4 * pi * epsilon_0 * r_pos.^2));
% Calculate electric field components in x, y, and z directions
Ex_pos = E_magnitude_pos .* ((x - pos_charge(1)) ./ r_pos);
Ey_pos = E_magnitude_pos .* ((y - pos_charge(2)) ./ r_pos);
Ez_pos = E_magnitude_pos .* ((z - pos_charge(3)) ./ r_pos);
% Calculate force on test charge at the origin
F_x_pos = Q_pos * (Ex_pos(7, 7, 7)); % Force at the test charge location
F_y_pos = Q_pos * (Ey_pos(7, 7, 7));
F_z_pos = Q_pos * (Ez_pos(7, 7, 7));
% Create a figure for the positive charge
figure;
hold on;
% Plot the positive charge as a filled circle
plot3(pos_charge(1), pos_charge(2), pos_charge(3), 'ro', 'MarkerFaceColor', 'r', 'MarkerSize', 10,
'DisplayName', 'Positive Charge (1 nC)'); % Positive charge
% Plot the test charge at the origin as a filled circle
plot3(test_charge(1), test_charge(2), test_charge(3), 'go', 'MarkerFaceColor', 'g', 'MarkerSize', 10,
'DisplayName', 'Test Charge (1 nC)'); % Test charge
% Plot the electric field vectors using quiver3
quiver3(x(1:3:end, 1:3:end, 1:3:end), ...
y(1:3:end, 1:3:end, 1:3:end), ...
z(1:3:end, 1:3:end, 1:3:end), ...
Ex_pos(1:3:end, 1:3:end, 1:3:end), ...
Ey_pos(1:3:end, 1:3:end, 1:3:end), ...
Ez_pos(1:3:end, 1:3:end, 1:3:end), ...
'b', 'AutoScale', 'on', 'LineWidth', 1.5, 'DisplayName', 'Electric Field Vectors'); % Electric
field vectors
% Plot the force vector acting on the test charge
quiver3(test_charge(1), test_charge(2), test_charge(3), F_x_pos, F_y_pos, F_z_pos, 'k',
'AutoScale', 'on', 'LineWidth', 2, 'DisplayName', 'Force on Test Charge');
% Set labels and title
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Effect of Positive Charge on Test Charge');
% Create a legend
legend('Location', 'Best');
grid on;
axis equal;
hold off;
%% Effect of Negative Charge
% Calculate distances from the negative charge location
r_neg = sqrt((x - neg_charge(1)).^2 + (y - neg_charge(2)).^2 + (z - neg_charge(3)).^2);
% Avoid division by zero
r_neg(r_neg == 0) = eps;
% Electric field intensity magnitude for the negative charge
E_magnitude_neg = (Q_neg ./ (4 * pi * epsilon_0 * r_neg.^2));
% Calculate electric field components in x, y, and z directions
Ex_neg = E_magnitude_neg .* ((x - neg_charge(1)) ./ r_neg);
Ey_neg = E_magnitude_neg .* ((y - neg_charge(2)) ./ r_neg);
Ez_neg = E_magnitude_neg .* ((z - neg_charge(3)) ./ r_neg);
% Calculate force on test charge at the origin
F_x_neg = Q_neg * (Ex_neg(7, 7, 7)); % Force at the test charge location
F_y_neg = Q_neg * (Ey_neg(7, 7, 7));
F_z_neg = Q_neg * (Ez_neg(7, 7, 7));
% Create a figure for the negative charge
figure;
hold on;
% Plot the negative charge as a filled circle
plot3(neg_charge(1), neg_charge(2), neg_charge(3), 'bo', 'MarkerFaceColor', 'b', 'MarkerSize',
10, 'DisplayName', 'Negative Charge (-1 nC)'); % Negative charge
% Plot the test charge at the origin as a filled circle
plot3(test_charge(1), test_charge(2), test_charge(3), 'go', 'MarkerFaceColor', 'g', 'MarkerSize', 10,
'DisplayName', 'Test Charge (1 nC)'); % Test charge
% Plot the electric field vectors using quiver3
quiver3(x(1:3:end, 1:3:end, 1:3:end), ...
y(1:3:end, 1:3:end, 1:3:end), ...
z(1:3:end, 1:3:end, 1:3:end), ...
Ex_neg(1:3:end, 1:3:end, 1:3:end), ...
Ey_neg(1:3:end, 1:3:end, 1:3:end), ...
Ez_neg(1:3:end, 1:3:end, 1:3:end), ...
'b', 'AutoScale', 'on', 'LineWidth', 1.5, 'DisplayName', 'Electric Field Vectors'); % Electric
field vectors
% Plot the force vector acting on the test charge
quiver3(test_charge(1), test_charge(2), test_charge(3), F_x_neg, F_y_neg, F_z_neg, 'k',
'AutoScale', 'on', 'LineWidth', 2, 'DisplayName', 'Force on Test Charge');
% Set labels and title
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Effect of Negative Charge on Test Charge');
% Create a legend
legend('Location', 'Best');
grid on;
axis equal;
hold off;
Explanation of the Code:
1. Charge Definitions:
o Two charges are defined: a positive charge and a negative charge, each placed in 3D
space.
o A test charge is defined at the origin (0,0,0) to visualize how it interacts with the electric
field.
2. Electric Field Calculation:
o Electric fields due to both charges are calculated using the distance from each charge
and the formulas for electric fields.
3. Force Calculation:
o The force on the test charge is calculated using the formula F=q⋅E where q is the test
charge and E is the electric field vector.
4. Visualization:
o The electric field vectors are plotted using quiver3.
o The forces acting on the test charge are also represented as arrows starting from the
origin, indicating the direction and magnitude of the force experienced by the test
charge.
5. Legend and Labels:
o A legend is created to indicate which colors represent the positive and negative charges
and the force on the test charge.
Exercise:
Q1) for the code given in Task 1 and Task 3 give comments for each line of code.
Q2) Write a Matlab code for the problem statement mentioned below
CONCLUSION