%% BField calculation on the strip
clear, close all;
mu = 4*pi*1e-7;
e  = 1.6e-19;
V  = 100;
me = 9.1e-31;
d  = 1e-3;
tf = d*sqrt(2*me/(e*V));
n = 100;
vect_time = linspace(0,tf,n);
xmin = -1e-3;
xmax =  1e-3;
ymin = -1e-3;
ymax =  1e-3;
zmin =  0;
zmax = 1e-13;
x = linspace(-1e-3,1e-3,100);
y = linspace(-1e-3,1e-3,100);
[x,y] = meshgrid(x,y);

%  bx = mu*e^2*V*t/(4*pi*d*me)*(-y)./(x.^2+y.^2+(d-e*V*t^2/(2*d*me))^2).^(3/2);
%  by = mu*e^2*V*t/(4*pi*d*me)*x./(x.^2+y.^2+(d-e*V*t^2/(2*d*me))^2).^(3/2);
% 
% figure(1)
% quiver(bx,by,x,y);
% 
 scrsz = get(0,'ScreenSize');
figure('Position',[1 scrsz(4) scrsz(3) scrsz(4)])
axis([xmin xmax ymin ymax zmin zmax]);

set(gca,'nextplot','replacechildren');
for i=1:n
    t = vect_time(1,i);
    ix = e^2*V*t/(4*pi*d*me)*(-y)./(x.^2+y.^2+(d-e*V*t^2/(2*d*me))^2).^(3/2);
    iy = e^2*V*t/(4*pi*d*me)*(-x)./(x.^2+y.^2+(d-e*V*t^2/(2*d*me))^2).^(3/2);
    surf(x,y,ix.^2+iy.^2,'EdgeColor','none');
    F(i) = getframe;
end
% 
% movie(F,1,5);
% movie2avi(F,'current.avi','compression','None');
% 
% clear t;
% 
% r = linspace(0,2e-3,100);
% figure('Position',[1 scrsz(4) scrsz(3) scrsz(4)])
% axis([xmin 2*xmax zmin 1e-6]);
% 
% set(gca,'nextplot','replacechildren');
% for i=90:90
%     t = vect_time(1,i);
%     im = e^2*V*t/(4*pi*d*me)*r./(r.^2+(d-e*V*t^2/(2*d*me))^2).^(3/2);
%     plot(r,im);
%     F2(i) = getframe;
% end
% 
% movie(F2,1,5);
% movie2avi(F2,'current2.avi','compression','None');
% 
% clear t;

figure(3)
hold on
r = 1e-5;
t = vect_time;
pulse = -e^2*V*t/(4*pi*d*me).*(sqrt(1./(1e-4+(d-e*V*t.^2/(2*d*me)).^2))-1./(d-e*V*t.^2/(2*d*me)));
pulse11= -e^2*V*t/(4*pi*d*me).*(sqrt(1./(1e-6+(d-e*V*t.^2/(2*d*me)).^2))-1./(d-e*V*t.^2/(2*d*me)));
plot(t,pulse,'b');
plot(t,pulse11,'r');
d = d/2;
tf = d*sqrt(2*me/(e*V));
vect_time = linspace(0,tf,n);
t = vect_time;
pulse2 = -e^2*V*t/(4*pi*d*me).*(sqrt(1./(1e-4+(d-e*V*t.^2/(2*d*me)).^2))-1./(d-e*V*t.^2/(2*d*me)));
plot(t,pulse2,'r');
d = d*2;
V = V*2;
tf = d*sqrt(2*me/(e*V));
vect_time = linspace(0,tf,n);
t = vect_time;
pulse3 = -e^2*V*t/(4*pi*d*me).*(sqrt(1./(1e-4+(d-e*V*t.^2/(2*d*me)).^2))-1./(d-e*V*t.^2/(2*d*me)));
plot(t,pulse3,'g');
xlabel('time')
ylabel('amplitude of excitation')

