Question: Can you help me to do these question ? From the code worked on in exercise 4 of the work in the laboratory section, explain
Can you help me to do these question ?
From the code worked on in exercise 4 of the work in the laboratory section, explain each section in detail, so that the whole process can be understood. If you use commands that have not been reviewed in previous classes, explain given one.
Matlab Code exercise 4:
clc clear all close all %Inputs % Number of grid point [N = 1001] N = 1001; %Charge Q=[20,0,0,0,0] Q = [20, 0, 0, 0, 0] .* 1e-6; % Radius of circular charged conductor; a = 0.2; %X & Y components of position of charges [0, 0, 0, 0, 0] xC=[0, 0, 0,0,0]; yC=[0, 0, 0,0,0]; %5 random charges uncomment to run the program for 5 random charges %Q=(1+9.*rand(5,1)).*1e-6; %xC=-2 + 4 .* rand(5,1); %yC=-2 + 4 .* rand(5,1); % constants eps0 = 8.854e-12; kC = 1/(4*pi*eps0); % Dimensions of region / saturation levels
%[dimensionsofregion-2to2/minR=1e-6/Esat=1e6/Vsat=1e6] minX = -2; maxX = 2; minY = -2; maxY = 2; minR = 1e-6; minRx = 1e-6; minRy = 1e-6; Vsat = kC * max(abs(Q)) / a; Esat = kC * max(abs(Q)) / a^2; %SETUP % fields V = zeros(N,N); Ex = zeros(N,N); Ey = zeros(N,N); % [2D] region x = linspace(minX,maxX,N); y = linspace(minY, maxY,N); % color of charged object + red / - black col1 = [1 0 0]; if Q(1) < 0; col1 = [0 0 0]; end; % grid positions [xG, yG] = meshgrid(x,y);
%Calculation for n = 1 : 5 Rx = xG - xC(n); Ry = yG - yC(n); index = find(abs(Rx)+ abs(Ry) == 0); Rx(index) = minRx; Ry(index) = minRy; R = sqrt(Rx.^2 + Ry.^2); R(R==0) = minR; V = V + kC .* Q(n) ./ (R); R3 = R.^3; Ex = Ex + kC .* Q(n) .* Rx ./ R3; Ey = Ey + kC .* Q(n) .* Ry ./ R3; end E = sqrt(Ex.^2 + Ey.^2); % GRAPHICS ================================ figure(8) set(gcf,'units','normalized','position',[0.73 0.1 0.23 0.32]); hold on index1 = 51 : 50 : 951;
index1 = [index1 500 502]; index2 = index1; p1 = xG(index1, index2); p2 = yG(index1, index2); % scaling of electric field lines: unit length p3 = Ex(index1, index2)./(E(index1,index2)); p4 = Ey(index1, index2)./(E(index1,index2)); % no scaling of electric field lines % p3 = Ex(index1, index2); p4 = Ey(index1, index2); h = quiver(p1,p2,p3,p4,'autoscalefactor',0.8); set(h,'color',[0 0 1],'linewidth',1.2) hold on % charge pos = [-a, -a, 2*a, 2*a]; h = rectangle('Position',pos,'Curvature',[1,1]); set(h,'FaceColor',col1,'EdgeColor',col1); xlabel('x [m]'); ylabel('y [m]'); title('Carga Positiva'); set(gca,'xLim',[-2,2]); set(gca,'yLim', [-2, 2]); axis([-2 2 -2 2]); axis equal box on
%% Pregunta 4 carga negativa
clc clear all close all %Inputs % Number of grid point [N = 1001] N = 1001; %Charge Q=[20,0,0,0,0] Q = [20, 0, 0, 0, 0] .* -1e-6; % Radius of circular charged conductor; a = 0.2; %X & Y components of position of charges [0, 0, 0, 0, 0] xC=[0, 0, 0,0,0]; yC=[0, 0, 0,0,0]; %5 random charges uncomment to run the program for 5 random charges %Q=(1+9.*rand(5,1)).*1e-6; %xC=-2 + 4 .* rand(5,1); %yC=-2 + 4 .* rand(5,1); % constants eps0 = 8.854e-12; kC = 1/(4*pi*eps0); % Dimensions of region / saturation levels
%[dimensionsofregion-2to2/minR=1e-6/Esat=1e6/Vsat=1e6] minX = -2; maxX = 2; minY = -2; maxY = 2; minR = 1e-6; minRx = 1e-6; minRy = 1e-6; Vsat = kC * max(abs(Q)) / a; Esat = kC * max(abs(Q)) / a^2; %SETUP % fields V = zeros(N,N); Ex = zeros(N,N); Ey = zeros(N,N); % [2D] region x = linspace(minX,maxX,N); y = linspace(minY, maxY,N); % color of charged object + red / - black col1 = [1 0 0]; if Q(1) < 0; col1 = [0 0 0]; end; % grid positions [xG, yG] = meshgrid(x,y);
%Calculation for n = 1 : 5 Rx = xG - xC(n); Ry = yG - yC(n); index = find(abs(Rx)+ abs(Ry) == 0); Rx(index) = minRx; Ry(index) = minRy; R = sqrt(Rx.^2 + Ry.^2); R(R==0) = minR; V = V + kC .* Q(n) ./ (R); R3 = R.^3; Ex = Ex + kC .* Q(n) .* Rx ./ R3; Ey = Ey + kC .* Q(n) .* Ry ./ R3; end E = sqrt(Ex.^2 + Ey.^2); % GRAPHICS ================================ figure(8) set(gcf,'units','normalized','position',[0.73 0.1 0.23 0.32]); hold on index1 = 51 : 50 : 951;
index1 = [index1 500 502]; index2 = index1; p1 = xG(index1, index2); p2 = yG(index1, index2); % scaling of electric field lines: unit length p3 = Ex(index1, index2)./(E(index1,index2)); p4 = Ey(index1, index2)./(E(index1,index2)); % no scaling of electric field lines % p3 = Ex(index1, index2); p4 = Ey(index1, index2); h = quiver(p1,p2,p3,p4,'autoscalefactor',0.8); set(h,'color',[0 0 1],'linewidth',1.2) hold on % charge pos = [-a, -a, 2*a, 2*a]; h = rectangle('Position',pos,'Curvature',[1,1]); set(h,'FaceColor',col1,'EdgeColor',col1); xlabel('x [m]'); ylabel('y [m]'); title('Carga Negativa'); set(gca,'xLim',[-2,2]); set(gca,'yLim', [-2, 2]); axis([-2 2 -2 2]); axis equal box on
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
