getf('multilayer.sci');
function [R,T]=reflexionMetal(e)
    npts=length(e);
    R=zeros(npts);
    T=zeros(npts);
    for p=1:npts,
        [R(p),T(p)]=coefficientsRTpuissances(1,1,%pi/4,1.5,1,[1.44-%i*5.32,e(p)]);
    end,
endfunction
            
e=[0:0.0005:0.02];
[R,T]=reflexionMetal(e);
            
plotA=scf();
plot2d(e,R,style=5);
plot2d(e,T,style=9);
legend('R','T');
xtitle('Aluminium','e/lambda','');
            
e=0.0078;
equ=e*589

function [R,T]=reflexionSemiRef(thetai)
    npts=length(thetai);
    R=zeros(npts);
    T=zeros(npts);
    for p=1:npts,
        [R(p),T(p)]=coefficientsRTpuissances(1,1,thetai(p),1.5,1,[1.44-%i*5.32,e]);
    end,
endfunction
            
thetai=[0:1:90];
[R,T]=reflexionSemiRef(thetai*%pi/180);
            
plotB=scf();
plot2d(thetai,R,style=5);
plot2d(thetai,T,style=9);
legend('R','T');
xtitle('Aluminium','theta');
            

function [phiTE,phiTM]=dephasage(thetai)
    npts=length(thetai);
    phiTE=zeros(npts);    phiTM=zeros(npts);
    for p=1:npts,
        [r,t]=coefficientsRT(1,1,thetai(p),1.5,1,[1.44-%i*5.32,e]);
        phiTE(p)=imag(log(r));
        [r,t]=coefficientsRT(1,1,thetai(p),1.5,0,[1.44-%i*5.32,e]);
        phiTM(p)=imag(log(r));
    end,
endfunction
            
thetai=[40:0.1:50];
[phiTE,phiTM]=dephasage(thetai);
plotC=scf();
plot2d(thetai,phiTE/%pi,style=5,rect=[40,-1,50,1]);
plot2d(thetai,phiTM/%pi,style=9);
legend('phiTE','phiTM');
xtitle('Aluminium','theta','phi/pi');
            

function e=epaisseurMaxReflex(lambda,thetai,n)
    cosTheta=sqrt(1-(sin(thetai)/n)^2);
    e=lambda/4/(n*cosTheta)
endfunction
            

function R=coefMaxReflex(lambda,thetai,n)
    npts=length(n);
    R=zeros(npts);
    for p=1:npts,
        [R(p),T]=coefficientsRTpuissances(lambda,1,thetai,1.5,1,[n(p),epaisseurMaxReflex(lambda,thetai,n(p))]);
    end,
endfunction
            
n=[1:0.01:3];
R=coefMaxReflex(500,%pi/4,n);
            
plotD=scf();
plot2d(n,R,style=5);
xtitle('dielectrique : R maximal','n','R');
            

function R=coefMaxReflexB(lambda,thetai,n,e)
    npts=length(lambda);
    R=zeros(npts);
    for p=1:npts,
        [R(p),T]=coefficientsRTpuissances(lambda(p),1,thetai,1.5,1,[n,e]);
    end,
endfunction
            

n=2.43;
e=epaisseurMaxReflex(500,%pi/4,n);
lambda=[400:1:700];
R=coefMaxReflexB(lambda,%pi/4,n,e);
            
plotE=scf();
plot2d(lambda,R,style=5,rect=[400,0,700,0.5]);
xtitle('dielectrique : R maximal','lambda','R')
            

function sys=multicouchePeriodique(lambda,N,n1,n2)
    e1=epaisseurMaxReflex(lambda,%pi/4,n1);
    e2=epaisseurMaxReflex(lambda,%pi/4,n2);
    sys=zeros(2*N,2);
    for c=1:N,
        sys(2*c-1,1)=n1;
        sys(2*c-1,2)=e1;
        sys(2*c,1)=n2;
        sys(2*c,2)=e2;
    end,
endfunction
            

function R=coefReflexion(lambda,sys)
    npts=length(lambda);
    R=zeros(npts);
    for p=1:npts,
        [R(p),T]=coefficientsRTpuissances(lambda(p),1,%pi/4,1.5,1,sys);
    end,
endfunction
            

lambda=[400:1:700];
n1=1.8;
n2=1.4;
sys1=multicouchePeriodique(500,1,n1,n2);
R1=coefReflexion(lambda,sys1);
sys2=multicouchePeriodique(500,2,n1,n2);
R2=coefReflexion(lambda,sys2);
sys3=multicouchePeriodique(500,3,n1,n2);
R3=coefReflexion(lambda,sys3);
sys4=multicouchePeriodique(500,20,n1,n2);
R4=coefReflexion(lambda,sys4);
            
plotF=scf();
plot2d(lambda,R1,style=5,rect=[400,0,700,1]);
plot2d(lambda,R2,style=9);
plot2d(lambda,R3,style=12);
plot2d(lambda,R4,style=15);
legend('N=1','N=2','N=3','N=20');
xtitle("Multicouche periodique : n1=1.8 n2=1.4","lambda (nm)","R");
            
