フィルターのクリア

Plot E-field ?

4 ビュー (過去 30 日間)
sanbadgerdude
sanbadgerdude 2016 年 3 月 25 日
回答済み: Chaitanya 2023 年 7 月 11 日
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

回答 (1 件)

Chaitanya
Chaitanya 2023 年 7 月 11 日
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!

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by