Develop a MTALB code to determine the electric field due to the following charge
ID: 2072701 • Letter: D
Question
Develop a MTALB code to determine the electric field due to the following charge distributions: a point charge, an infinite line charge, and an infinite surface charge. The code must ask the user to select n number of charge distributions, which could be the same or different. For each source, the code must ask the user to input the location of the source. The code must ask the user to enter the position of the field point. The code must presents numerically the fields of the individual sources and the total field due to the n sources. Use the Cartesian coordinate system.Explanation / Answer
n={1,2,3};
[x,y,z]=meshgrid(-1:0.05:1,0.001:0.05:1,-1:0.05:1);
if n=1
E=1./(x.^2+y.^2+z.^2);
figure(1);
slice(x,y,z,log(E),[-1:0.05:1],[0.001:0.05:1],[-1:0.05:1]);
shading interp;
colormap hsv;
xlabel('x');
ylabel('y');
zlabel('z');
title('Electric field due to point charge');
elseif n=2
E=1./sqrt(x.^2+y.^2);
figure(2);
slice(x,y,z,log(E),[-1:0.05:1],[0.001:0.05:1],[-1:0.05:1]);
shading interp;
colormap hsv;
xlabel('x');
ylabel('y');
zlabel('z');
title('Electric field due to line charge');
else n=3
E=1./((x.^3+y.^3+z.^3).^(1/3));
figure(1);
slice(x,y,z,log(E),[-1:0.05:1],[0.001:0.05:1],[-1:0.05:1]);
shading interp;
colormap hsv;
xlabel('x');
ylabel('y');
zlabel('z');
title('Electric field due to surface charge');
axis square;
colorbar;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.