K=8.99*10^9;
n=input('Enter number of charges: ');
for i=1:n
q(i)=input('Enter the charge in coulombs: ');
end
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: ');
disp('Enter the coordinates for the source point for the four charges :');
for m=1:n
x(m)=input('Enter x coordinate : ' );
y(m)=input('Enter y coordinate : ');
z(m)=input('Enter z coordinate : ');
xi(m)=xf-x(m);
yi(m)=yf-y(m);
zi(m)=zf-z(m);
end
sum=0;
for m=1:n
mag(m)=(sqrt(xi(m)^2 + yi(m)^2 + zi(m)^2))^3;
sum=sum+q(m)*([xi(m),yi(m),zi(m)]/mag(m));
end
disp('The electric field intensity is :');
ef=K*sum;
ef
1 Comment
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/511074-i-have-made-a-code-for-calculating-the-electric-field-intensity-for-n-charges-i-need-help-plotting#comment_810608
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/511074-i-have-made-a-code-for-calculating-the-electric-field-intensity-for-n-charges-i-need-help-plotting#comment_810608
Sign in to comment.