THIS REQUIRES YOU TO USE MATLAB (preferable the latest version possible). PLEASE DO SO AND UPLOAD YOUR CODE. Goal: The intent of this problem is to have you visualize electric fields and understand spatial relationships between charge distributions and E. Instructions: Combine all parts of the problem into a single file and upload either a .pdf or image file of all parts of the question. 1. Develop a code that can plot the electric field produced by two point charges separated by a distance d where the origin is in the middle of the two charges. You may use whatever language is most convenient for you. (a) Produce a plot of the electric field produced by a dipole (equal and opposite point charges) (b) Produce a plot of the electric field of two identical point charges (c) Produce a plot two charges with random charge values (keep them reasonably close in magnitude) (d) Discuss the electric field distributions for the three cases above. Take note of where the electric field is zero, where it is maximal and the shape it takes. (e) Include a copy of your code. To help get you started, below I outline the steps that are required to generate these plots. As a starting point provide some preliminary code for MATLAB that you can complete to finish the task. You can modify/build from this as you see fit. Two key functions to note in MATLAB are meshgrid() and quiver(). You'll find these used in the code below and they are helpful for this problem. **Program steps... Create a grid of points with varying x,y,z coordinates (like graph paper) Place a charge with some magnitude Q at some coordinate Import formula for a point charge broken into cartesian unit vectors For every point in the x-y-z grid (observation point) find the distance between the current point and the point chargeQ Use this distance to define the magnitudes of the E-field components Determine the unit vector of the separation vector between every observation point and the location of charge Q. Use the magnitude, unit vector, and E field of a point charge to find Ex, Ey, and Ez. Save the values of Ex and Ey and Ez at the observation point to three arrays Create a vector field plot of the E field at each point in the grid Here is some MATLAB code to get you started: %constants eo = 8.8e-12; %[F/m] electric constant pi = 3.14159; del = 0.5; span = -4:del:4; half_length = floor(length(axis)/2); [X, Y, Z] = meshgrid(span, span, span); %This function creates your grid of points %define charge magnitude/location R1_x = X - P1_x; %take each observation point in the meshgrid and computs its distance from the charge in x R1_y = Y – P1_y; %take each observation point in the meshgrid and computs its distance from the charge in y R1_z = Z – P1_z; %take each observation point in the meshgrid and computs its distance from the charge in z R2_x = X - P2_x; %repeat for charge 2 R2_y = Y – P2_y; R2_z = Z – P2_z; R1_mag = sqrt(R1_x.^2 + Y.^2 + Z.^2); R2_mag = sqrt(R2_x.^2 + Y.^2 + Z.^2); %define the unit vectors %Calculate the E field components for each charge %Use superposition to find the total electric field %now we will plot the results figure; %plot in xy plane quiver(X(:,:,half_length),Y(:,:,half_length),Etot_x(:,:,half_length), Etot_y(:,:,half_length),3); axis equal; axis tight; xlabel('X'); ylabel('Y'); p1 = nsidedpoly(1000,'Center', [P1_x-del 0], 'Radius',0.5); p2 = nsidedpoly(1000,'Center', [P2_x+del 0], 'Radius',0.5); hold on; plot(p1, 'FaceColor', 'r'); plot(p2, 'FaceColor', 'b'); axis equal; axis tight; hold off figure; %plot in 3d quiver3(X,Y,Z,Etot_x, Etot_y, Etot_z,3); xlabel('X'); ylabel('Y'); zlabel('Z');
THIS REQUIRES YOU TO USE MATLAB (preferable the latest version possible). PLEASE DO SO AND UPLOAD YOUR CODE.
Goal: The intent of this problem is to have you visualize electric fields and understand spatial relationships between charge distributions and E.
Instructions: Combine all parts of the problem into a single file and upload either a .pdf or image file of all parts of the question.
1. Develop a code that can plot the electric field produced by two point charges separated by a distance d where the origin is in the middle of the two charges. You may use whatever language is most convenient for you.
(a) Produce a plot of the electric field produced by a dipole (equal and opposite point charges)
(b) Produce a plot of the electric field of two identical point charges
(c) Produce a plot two charges with random charge values (keep them reasonably close in magnitude)
(d) Discuss the electric field distributions for the three cases above. Take note of where the electric field is zero, where it is maximal and the shape it takes.
(e) Include a copy of your code.
To help get you started, below I outline the steps that are required to generate these plots. As a starting point provide some preliminary code for MATLAB that you can complete to finish the task. You can modify/build from this as you see fit. Two key functions to note in MATLAB are meshgrid() and quiver(). You'll find these used in the code below and they are helpful for this problem.
**Program steps...
Create a grid of points with varying x,y,z coordinates (like graph paper)
Place a charge with some magnitude Q at some coordinate
Import formula for a point charge broken into cartesian unit
For every point in the x-y-z grid (observation point) find the distance between the current point and the point chargeQ
Use this distance to define the magnitudes of the E-field components
Determine the unit vector of the separation vector between every observation point and the location of charge Q.
Use the magnitude, unit vector, and E field of a point charge to find Ex, Ey, and Ez.
Save the values of Ex and Ey and Ez at the observation point to three arrays
Create a vector field plot of the E field at each point in the grid
Here is some MATLAB code to get you started:
%constants
eo = 8.8e-12; %[F/m] electric constant
pi = 3.14159;
del = 0.5;
span = -4:del:4;
half_length = floor(length(axis)/2);
[X, Y, Z] = meshgrid(span, span, span); %This function creates your grid of points
%define charge magnitude/location
R1_x = X - P1_x; %take each observation point in the meshgrid and computs its distance from the charge in x
R1_y = Y – P1_y; %take each observation point in the meshgrid and computs its distance from the charge in y
R1_z = Z – P1_z; %take each observation point in the meshgrid and computs its distance from the charge in z
R2_x = X - P2_x; %repeat for charge 2
R2_y = Y – P2_y;
R2_z = Z – P2_z;
R1_mag = sqrt(R1_x.^2 + Y.^2 + Z.^2);
R2_mag = sqrt(R2_x.^2 + Y.^2 + Z.^2);
%define the unit vectors
%Calculate the E field components for each charge
%Use superposition to find the total electric field
%now we will plot the results
figure;
%plot in xy plane
quiver(X(:,:,half_length),Y(:,:,half_length),Etot_x(:,:,half_length), Etot_y(:,:,half_length),3);
axis equal;
axis tight;
xlabel('X');
ylabel('Y');
p1 = nsidedpoly(1000,'Center', [P1_x-del 0], 'Radius',0.5);
p2 = nsidedpoly(1000,'Center', [P2_x+del 0], 'Radius',0.5);
hold on;
plot(p1, 'FaceColor', 'r');
plot(p2, 'FaceColor', 'b');
axis equal;
axis tight;
hold off
figure;
%plot in 3d
quiver3(X,Y,Z,Etot_x, Etot_y, Etot_z,3);
xlabel('X');
ylabel('Y');
zlabel('Z');
Step by step
Solved in 4 steps with 2 images