Plot E-field ?

13 Ansichten (letzte 30 Tage)
sanbadgerdude
sanbadgerdude am 25 Mär. 2016
Beantwortet: Chaitanya am 11 Jul. 2023
Here is my code. It calculates e-field at a point (PE) based on multiple charges (NOC) spaced along the Z-axis. Loops through calculating for each point and sums it up to give E. I want to plot the results for E.
clc;
clear all;
NOC = 9;
Q = 0.3e-6;
PE = [2 3 4];
Eps0 = 8.854e-12;
E = [0 0 0];
for i=(-(NOC-1)/2:(NOC-1)/2)
PC=[0 0 i];
R=(PE-PC);
E1=(Q*R)/(4*pi*Eps0*norm(R)^3);
E=E+E1
end
(results)
E =
439.4929 659.2394 451.1651

Antworten (1)

Chaitanya
Chaitanya am 11 Jul. 2023
To plot the results for the electric field (E), you can use the plot3 function in MATLAB. Here's an example of how you can modify your code to plot the values of E:
clc;
clear all;
NOC = 9;
Q = 0.3e-6;
PE = [2 3 4];
Eps0 = 8.854e-12;
E = [0 0 0];
% Arrays to store the calculated electric field values
x = [];
y = [];
z = [];
for i = (-(NOC-1)/2 : (NOC-1)/2)
PC = [0 0 i];
R = (PE - PC);
E1 = (Q * R) / (4 * pi * Eps0 * norm(R)^3);
E = E + E1;
% Store the electric field values for plotting
x = [x E(1)];
y = [y E(2)];
z = [z E(3)];
end
% Plot the electric field values
figure;
plot3(x, y, z, 'o-');
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Electric Field (E) at each point');
% Optional: Add gridlines to the plot
grid on;
This modified code will calculate the electric field values at each point and store them in separate arrays (x, y, z). Then, the plot3 function is used to create a 3D plot of the electric field values. The xlabel, ylabel, and zlabel functions are used to label the axes, and the title function sets the title of the plot. Finally, the grid on command adds gridlines to the plot for better visualization.
You can run this code in MATLAB to plot the electric field values and visualize them in a 3D plot.
Hope this helps!

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by