clear all
close all
clc
tic
% ========================================================================
% INPUTS
% ========================================================================
% Number of charges
NQ = 100;
% Charge
Q0 = 10e-6;
% constants
eps0 = 8.854e-12;
kC = 1/(4*pi*eps0);
% Charges
Q = -Q0 .* ones(1,NQ);
Q(1+NQ/2:NQ) = Q0;
xC(1:NQ/2) = linspace(x1,x2,NQ/2);
xC(1+NQ/2:NQ) = linspace(x1,x2,NQ/2);
yC(1:NQ/2) = y1; yC(1+NQ/2:NQ) = y2;
% 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);
% Grid positions
[xG, yG] = meshgrid(x,y);
% =======================================================================
% CALCULATION: POTENTIAL & ELECTRIC FIELD
% =======================================================================
for n = 1 : NQ
Rx = xG - xC(n);
Ry = yG - yC(n);
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);
if max(max(E)) >= Esat; E(E > Esat) = Esat; end;
if min(min(E)) <= -Esat; E(E < -Esat) = -Esat; end;
%%
figure(1) % 11111111111111111111111111111111111111111111111111111111111
set(gcf,'units','normalized','position',[0.01 0.52 0.23 0.32]);
surf(xG,yG,V./1e6);
rotate3d
view(76,32);
set(gca,'fontsize',12)
set(gca,'xLim',[-2, 2]); set(gca,'yLim',[-2, 2]);
shading interp;
h = colorbar;
h.Label.String = 'V [ MV ]';
colormap(parula);
axis square
box on
%%
figure(2) %2222222222222222222222222222222222222222222222222222222222222
set(gcf,'units','normalized','position',[0.25 0.52 0.23 0.32]);
zP = V./1e6;
contourf(xG,yG,zP,16);
%set(gca,'xLim',[-5,5]); set(gca,'yLim', [-5, 5]);
%set(gca,'xTick',-5:5); set(gca,'yTick', -5:5);
hold on
% charged conductors
col = col2;
for n = 1:NQ/2
pos = [-a+xC(n), -a+yC(n), 2*a, 2*a];
h = rectangle('Position',pos,'Curvature',[1,1]);
set(h,'FaceColor',col,'EdgeColor',col);
end
col = col1;
for n = 1+NQ/2:NQ
pos = [-a+xC(n), -a+yC(n), 2*a, 2*a];
h = rectangle('Position',pos,'Curvature',[1,1]);
set(h,'FaceColor',col,'EdgeColor',col);
end
set(gca,'fontsize',12);
axis square
box on
%%
figure(3) % 33333333333333333333333333333333333333333333333333333333333
set(gcf,'units','normalized','position',[0.49 0.52 0.23 0.32]);
c = 0; yStep = zeros(1,5);
%tt = num2str(yStep,2);
%tm1 = 'y = ';
%tm2 = tt;
%tm = [tm1 tm2];
tm = 'Potential profiles for different y values';
xlabel('x [m]'); ylabel('V [ MV ]');
set(gca,'fontsize',12)
h_title = title(tm);
set(h_title,'fontsize',12,'FontWeight','normal');
%set(gca,'xTick',-5:5);
tm1 = num2str(yStep(1),2);
tm2 = num2str(yStep(2),2); tm3 = num2str(yStep(3),2);
tm4 = num2str(yStep(4),2); tm5 = num2str(yStep(5),2);
%tm6 = num2str(yStep(6),3);
h = legend(tm1,tm2,tm3,tm4,tm5,'Orientation','horizontal');
set(h,'Location','northOutside');
%
%%
figure(4) % 4444444444444444444444444444444444444444444444444444444444
set(gcf,'units','normalized','position',[0.73 0.52 0.23 0.32]);
c = 0; yStep = zeros(1,5);
for n = ceil(N/2) : ceil(N/10): N
% for n = [1 11 21 31 41 51]
xP = xG(n,:); yP = E(n,:)./1e6;
plot(xP,yP,'linewidth',2);
hold on
c = c+1;
yStep(c) = yG(n,1);
end
tm1 = num2str(yStep(1),2);
tm2 = num2str(yStep(2),2); tm3 = num2str(yStep(3),2);
tm4 = num2str(yStep(4),2); tm5 = num2str(yStep(5),2);
h = legend(tm1,tm2,tm3,tm4,tm5);
set(h,'Orientation','horizontal','Location','northOutside');
set(gca,'fontsize',12);
box on;
%%
figure(5) % 5555555555555555555555555555555555555555555555555555555555
set(gcf,'units','normalized','position',[0.01 0.1 0.23 0.32]);
surf(xG,yG,E./1e6);
colorbar
shading interp
h = colorbar;
h.Label.String = '| E | [ MV/m ]';
rotate3d
view(30,50);
axis square
set(gca,'fontsize',12)
box on
%%
figure(6) % 66666666666666666666666666666666666666666666666666666666666
set(gcf,'units','normalized','position',[0.25 0.1 0.23 0.32]);
contourf(xG,yG,V./1e6,12)
hold on
% Charge 1
% ang = linspace(15,345,12);
% ang1 = deg2rad(ang);
% if Q(1) > 0;
p3 = Ex; p4 = Ey;
% else
% p3 = -Ex; p4 = -Ey;
% end
dx = xC(2)-xC(1);
%sx = -8*dx + xC(1): 2*dx: 8*dx + xC(end);
sx = -1.2:0.2:1.2;
L = length(sx);
sy = 0.45 .* ones(L,1);
h = streamline(xG,yG,p3,p4,sx,sy);
set(h,'linewidth',2,'color',[1 1 1]);
sy = -0.55 .* ones(L,1);
h = streamline(xG,yG,-p3,-p4,sx,sy);
set(h,'linewidth',2,'color',[1 1 1]);
% charged conductors
col = col2;
for n = 1:NQ/2
pos = [-a+xC(n), -a+yC(n), 2*a, 2*a];
h = rectangle('Position',pos,'Curvature',[1,1]);
set(h,'FaceColor',col,'EdgeColor',col);
end
col = col1;
for n = 1+NQ/2:NQ
pos = [-a+xC(n), -a+yC(n), 2*a, 2*a];
h = rectangle('Position',pos,'Curvature',[1,1]);
set(h,'FaceColor',col,'EdgeColor',col);
end
shading interp
h = colorbar;
h.Label.String = 'V [ MV ]';
h = colormap('parula');
beta = 0.5;
brighten(h,beta);
axis square;
box on;
%%
figure(7) % 7777777777777777777777777777777777777777777777777777777777
set(gcf,'units','normalized','position',[0.49 0.1 0.23 0.32]);
pcolor(xG,yG,E./1e6);
% charged conductors
col = col2;
for n = 1:NQ/2
pos = [-a+xC(n), -a+yC(n), 2*a, 2*a];
h = rectangle('Position',pos,'Curvature',[1,1]);
set(h,'FaceColor',col,'EdgeColor',col);
end
col = col1;
for n = 1+NQ/2:NQ
pos = [-a+xC(n), -a+yC(n), 2*a, 2*a];
h = rectangle('Position',pos,'Curvature',[1,1]);
set(h,'FaceColor',col,'EdgeColor',col);
end
shading interp
h = colorbar;
h.Label.String = '|E| [ MV/m ]';
axis square
set(gca,'fontsize',12)
box on
%%
figure(8) % 8888888888888888888888888888888888888888888888888888888888
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;
h = quiver(p1,p2,p3,p4,'autoscalefactor',0.8);
set(h,'color',[0 0 1],'linewidth',1.2)
hold on
% charged conductors
col = col2;
for n = 1:NQ/2
pos = [-a+xC(n), -a+yC(n), 2*a, 2*a];
h = rectangle('Position',pos,'Curvature',[1,1]);
set(h,'FaceColor',col,'EdgeColor',col);
end
col = col1;
for n = 1+NQ/2:NQ
pos = [-a+xC(n), -a+yC(n), 2*a, 2*a];
h = rectangle('Position',pos,'Curvature',[1,1]);
set(h,'FaceColor',col,'EdgeColor',col);
end
%%
toc