I have made a code for calculating the electric field intensity for n charges. I need help plotting the electric field intensity pl help !
165 views (last 30 days)
Vincent Abraham on 16 Mar 2020
%This is a program for calculating electric field for n number of charges
%where the source and field points are in cartesian coordinates.
%First, defining the proportionality constant
%Taking the input for n no. of charges
n=input('Enter number of charges: ');
q(i)=input('Enter the charge in coulombs: ');
%Taking the coordinates of the field point
disp('Enter the coordinates for the field point :');
xf=input('Enter x coordinate of the field point : ' );
yf=input('Enter y coordinate of the field point: ');
zf=input('Enter z coordinate of the field point: ');
%Taking the coordinates of n source points for n charges
disp('Enter the coordinates for the source point for the four charges :');
x(m)=input('Enter x coordinate : ' );
y(m)=input('Enter y coordinate : ');
z(m)=input('Enter z coordinate : ');
%field point - source point for getting vector r
%Performing the summation portion of the formula
mag(m)=(sqrt(xi(m)^2 + yi(m)^2 + zi(m)^2))^3;
%Finally multiplying it by K
disp('The electric field intensity is :');
Andreas Bernatzky on 16 Mar 2020
As darova already mentioned it is really annoying. You should think about a different user input.
But for visualizing I would suggest something like surf(), mesh().
Create a 2D matrix with the size of your [min,max] values for the cartesian xy-coordinates. Calculate the field intensity in each point. Than just use surf() or mesh() on your matrix. For every z-Coordinate i would create an extra 2D Matrix.
yourElectricField = rand(5,5); % create a random 2D matrix with the size of 5 in x and 5 in y
surf(yourElectricField); %simple visualization
Thats just my personal opinion of your problem because I do not know your application and neither I am a expert for electric fields but I think I get the problem.