clear
pack

t100=clock;

eta=.667;h=6.625*10^(-34);c=3*10^8;l=1.173*10^(-6);
ni=c/l;p=1.0*10^(-7.1);
g=80;kef=.04;t1=(22/9)*10^(-9);
q=1.6*10^(-19);
fe=kef*g+(2-1/g)*(1-kef);
ne=p*eta*t1/(h*ni);
sigma=(g*q*sqrt(ne*fe))/t1;m=(ne*g*q)/t1;
lambda=(sqrt(ne*fe))/(fe-1);
a1=[4.5 21 50 80 82 60 30 9 3.18];
a=10^9*(1/339.68).*a1;
m1=m.*a;
sigma1=sigma.*a;
%m1(1)=m;
%sigma1(1)=sigma;
x=(0:2:6000);
mi=m*10^9
sigmai=sigma*10^9
ui=1+(x-mi)./(lambda*sigmai);

u1=1+(x-m1(1))./(lambda*sigma1(1));
u2=1+(x-m1(2))./(lambda*sigma1(2));
u3=1+(x-m1(3))./(lambda*sigma1(3));
u4=1+(x-m1(4))./(lambda*sigma1(4));
u5=1+(x-m1(5))./(lambda*sigma1(5));
u6=1+(x-m1(6))./(lambda*sigma1(6));
u7=1+(x-m1(7))./(lambda*sigma1(7));
u8=1+(x-m1(8))./(lambda*sigma1(8));
u9=1+(x-m1(9))./(lambda*sigma1(9));
wi=(1./(sqrt(2*pi)*sigmai.*ui.^1.5)).*exp(-1.*(x-mi).^2 ./(2*sigmai^2 .*ui));
y=10^5 .*wi;
r=round(y);
sc=cumsum(y);

w1=(1./(sqrt(2*pi)*sigma1(1).*u1.^1.5)).*exp(-1.*(x-m1(1)).^2 ./(2*sigma1(1)^2 .*u1));
w2=(1./(sqrt(2*pi)*sigma1(2).*u2.^1.5)).*exp(-1.*(x-m1(2)).^2 ./(2*sigma1(2)^2 .*u2));
w3=(1./(sqrt(2*pi)*sigma1(3).*u3.^1.5)).*exp(-1.*(x-m1(3)).^2 ./(2*sigma1(3)^2 .*u3));
w4=(1./(sqrt(2*pi)*sigma1(4).*u4.^1.5)).*exp(-1.*(x-m1(4)).^2 ./(2*sigma1(4)^2 .*u4));
w5=(1./(sqrt(2*pi)*sigma1(5).*u5.^1.5)).*exp(-1.*(x-m1(5)).^2 ./(2*sigma1(5)^2 .*u5));
w6=(1./(sqrt(2*pi)*sigma1(6).*u6.^1.5)).*exp(-1.*(x-m1(6)).^2 ./(2*sigma1(6)^2 .*u6));
w7=(1./(sqrt(2*pi)*sigma1(7).*u7.^1.5)).*exp(-1.*(x-m1(7)).^2 ./(2*sigma1(7)^2 .*u7));
w8=(1./(sqrt(2*pi)*sigma1(8).*u8.^1.5)).*exp(-1.*(x-m1(8)).^2 ./(2*sigma1(8)^2 .*u8));
w9=(1./(sqrt(2*pi)*sigma1(9).*u9.^1.5)).*exp(-1.*(x-m1(9)).^2 ./(2*sigma1(9)^2 .*u9));
v=[sum(w1) sum(w2) sum(w3) sum(w4) sum(w5) sum(w6) sum(w7) sum(w8) sum(w9)];

c1=conv(w1,w2);
c2=conv(c1,w3);
c3=conv(c2,w4);
c4=conv(c3,w5);
c5=conv(c4,w6);
c6=conv(c5,w7);
c7=conv(c6,w8);
c8=conv(c7,w9);
vc=[sum(c1) sum(c2) sum(c3) sum(c4) sum(c5) sum(c6) sum(c7) sum(c8)];
d=round(wi.*10000);
s1=sum(d)
o=0:length(c1)-1;
o1=0:length(c2)-1;
o2=0:length(c3)-1;
o3=0:length(c4)-1;
o4=0:length(c5)-1;
o5=0:length(c6)-1;
o6=0:length(c7)-1;
o7=0:length(c8)-1;

semilogy(o,c1,'m')
hold on
%semilogy(x,w1,'b') 
%hold on
%semilogy(o1,c2,'c')
%semilogy(x,w2,'w')
%hold on
%semilogy(o2,c3,'r')
%semilogy(x,w7,'y')
%hold on
%semilogy(x,wi,'r')
%hold on
%semilogy(o3,c4,'y')
%hold on
%semilogy(o4,c5,'b')
%hold on
%semilogy(o5,c6,'g')
%hold on
%semilogy(o6,c7,'w')
%hold on
semilogy(o7,c8,'r')
%hold on
%axis([0 3000 10^(-100) 10^0]);grid
durata=etime(clock,t100)

b=sum(c8)
n=1;
t=14.68*n^(-.5);
g=(2*pi)^(-.5)*t^(-1)*exp(-x.^2./(2*t^2));
%cg=conv(c7,g);
%og=0:length(cg)-1;
%semilogy(og,cg,'b')

pack

m0=m.*a./10;
sigma0=sigma.*a./sqrt(10);
mi0=m*10^8
sigmai0=sigma*10^9/sqrt(10)
ui0=1+(x-mi0)./(lambda*sigmai0);
u01=1+(x-m0(1))./(lambda*sigma0(1));
u02=1+(x-m0(2))./(lambda*sigma0(2));
u03=1+(x-m0(3))./(lambda*sigma0(3));
u04=1+(x-m0(4))./(lambda*sigma0(4));
u05=1+(x-m0(5))./(lambda*sigma0(5));
u06=1+(x-m0(6))./(lambda*sigma0(6));
u07=1+(x-m0(7))./(lambda*sigma0(7));
u08=1+(x-m0(8))./(lambda*sigma0(8));
u09=1+(x-m0(9))./(lambda*sigma0(9));
wi0=(1./(sqrt(2*pi)*sigmai0.*ui0.^1.5)).*exp(-1.*(x-mi0).^2 ./(2*sigmai0^2 .*ui0));
y0=10^5 .*wi0;
r0=round(y0);
sc0=cumsum(y0);
s0=sum(r0)
w01=(1./(sqrt(2*pi)*sigma0(1).*u01.^1.5)).*exp(-1.*(x-m0(1)).^2 ./(2*sigma0(1)^2 .*u01));
w02=(1./(sqrt(2*pi)*sigma0(2).*u02.^1.5)).*exp(-1.*(x-m0(2)).^2 ./(2*sigma0(2)^2 .*u02));
w03=(1./(sqrt(2*pi)*sigma0(3).*u03.^1.5)).*exp(-1.*(x-m0(3)).^2 ./(2*sigma0(3)^2 .*u03));
w04=(1./(sqrt(2*pi)*sigma0(4).*u04.^1.5)).*exp(-1.*(x-m0(4)).^2 ./(2*sigma0(4)^2 .*u04));
w05=(1./(sqrt(2*pi)*sigma0(5).*u05.^1.5)).*exp(-1.*(x-m0(5)).^2 ./(2*sigma0(5)^2 .*u05));
w06=(1./(sqrt(2*pi)*sigma0(6).*u06.^1.5)).*exp(-1.*(x-m0(6)).^2 ./(2*sigma0(6)^2 .*u06));
w07=(1./(sqrt(2*pi)*sigma0(7).*u07.^1.5)).*exp(-1.*(x-m0(7)).^2 ./(2*sigma0(7)^2 .*u07));
w08=(1./(sqrt(2*pi)*sigma0(8).*u08.^1.5)).*exp(-1.*(x-m0(8)).^2 ./(2*sigma0(8)^2 .*u08));
w09=(1./(sqrt(2*pi)*sigma0(9).*u09.^1.5)).*exp(-1.*(x-m0(9)).^2 ./(2*sigma0(9)^2 .*u09));
v0=[sum(w01) sum(w02) sum(w03) sum(w04) sum(w05) sum(w06) sum(w07) sum(w08) sum(w09)];
c01=conv(w01,w02);
c02=conv(c01,w03);
c03=conv(c02,w04);
c04=conv(c03,w05);
c05=conv(c04,w06);
c06=conv(c05,w07);
c07=conv(c06,w08);
c08=conv(c07,w09);
vc0=[sum(c01) sum(c02) sum(c03) sum(c04) sum(c05) sum(c06) sum(c07) sum(c08)];
d=round(wi0.*10000);
s=sum(d)
o=0:length(c01)-1;
o1=0:length(c02)-1;
o2=0:length(c03)-1;
o3=0:length(c04)-1;
o4=0:length(c05)-1;
o5=0:length(c06)-1;
o6=0:length(c07)-1;
o7=0:length(c08)-1;

%semilogy(o,c01,'m')
%hold on
%semilogy(x,w01,'b') 
%hold on
%semilogy(o1,c02,'c')
%semilogy(x,w02,'w')
%hold on
%semilogy(o2,c03,'r')
semilogy(x,w09,'y')
hold on
%semilogy(x,wi0,'r')
%hold on
%semilogy(o,c1,'m')
%hold on
%semilogy(o3,c04,'y')
%hold on
%hold on
semilogy(o5,c06,'g')
%hold on
%semilogy(o6,c07,'w')
%hold on
semilogy(o7,c08,'c')
hold on
%cg0=conv(c07,g);
%og=0:length(cg0)-1;
%semilogy(og,cg0,'m')
axis([0 3400 10^(-80) 10^(1)]);grid
durata=etime(clock,t100)

