Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a MTALB code to determine the electric field due to the following charge

ID: 3730924 • Letter: D

Question

Develop a MTALB code to determine the electric field due to the following charge distributions; a point charge, infinite line charge, and infinite surface charge. The code must ask the user to select n number of charge distributions, which could be the same or different. The code must ask the user to input details of all sources (charge/charge densities and their locations). The code must also ask the user to enter the position of the observation point. The code must present 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;