Need help with Matlab! TASK 2: Computation of Electric Field at Arbitrary Point
ID: 2267841 • Letter: N
Question
Need help with Matlab!
TASK 2: Computation of Electric Field at Arbitrary Point P 1. Using MATLAB, write a program to determine the electric field components in the x, y, and z direction throughout a rectangular coordinate system (Equation 1). You will str need to write your program to prompt the user for the following input parameters: A. the number of point charges (up to 10) B. the relative dielectric constant of the medium (E) C. the value of the point charges (in nanocoulombs) D. the point charge locations in rectangular coordinates E. location point P where you want the field evaluated at E-0 2. Your output should provide the following information: a) The 5 input parameters (A through E above); b) The three electric field components at point P (E, Ey, E); c) Magnitude of the total electric field at point PExplanation / Answer
close all
clear all
clc
n=input('Enter number of point charges, upto 10: ');
eps_r=input('Enter the relative dielectric constant of the medium: ');
eps=eps_r*8.854*1e-12;
for i=1:n
Q(i)=input('Enter the value of charge in nanocoloumbs: ');
x(i)=input('Enter x location of the current charge particle: ');
y(i)=input('Enter y location of the current charge particle: ');
z(i)=input('Enter z location of the current charge particle: ');
end
xp=input('Enter x location of the Point P where field has to be evaluated: ');
yp=input('Enter y location of the Point P where field has to be evaluated: ');
zp=input('Enter z location of the Point P where field has to be evaluated: ');
disp('The following are the input parameters');
disp(' ');
disp(['The number of point charges is ',num2str(n)]);
disp(' ');
disp(['The relative dielectric constant of the medium is ',num2str(eps_r)]);
disp(' ');
for i=1:n
disp([num2str(i),' charge particle value is ',num2str(Q(i))]);
disp(' ');
end
for i=1:n
disp([num2str(i),' charge particle location is ',num2str(x(i)),' ',num2str(y(i)),' ',num2str(z(i))]);
disp(' ');
end
disp(['location at which we want to evaluate the electric field is ',num2str(xp),' ',num2str(yp),' ',num2str(zp)]);
disp(' ');
K=4*pi*eps*((x-xp).^2+(y-yp).^2+(z-zp).^2).^1.5;
Ex=1e-9*Q.*(x-xp)./K;
Ey=1e-9*Q.*(y-yp)./K;
Ez=1e-9*Q.*(z-zp)./K;
total_Ex=sum(Ex);
total_Ey=sum(Ey);
total_Ez=sum(Ez);
total_magnitude_at_P=sqrt(Ex.^2+Ey.^2+Ez.^2);
disp(['Ex due to different charge particles =',num2str(Ex)]);
disp(' ');
disp(['Ey due to different charge particles =',num2str(Ey)]);
disp(' ');
disp(['Ez due to different charge particles = ',num2str(Ez)]);
disp(' ');
disp(['Total Ex =',num2str(total_Ex)]);
disp(' ');
disp(['Total Ey =',num2str(total_Ey)]);
disp(' ');
disp(['Total Ez =',num2str(total_Ez)]);
disp(' ');
disp(['Total magnitude of E =',num2str(total_magnitude_at_P)]);
disp(' ');
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.