function invA=invb(T1,H,T2,s) 
Nz=size(H,3);
N=size(H,1);
if(s==0)
    s(1:Nz)=N;
end
i=1:s(Nz);
B(i,i)=inv(H(i,i,Nz));
for k=1:Nz-2
    i=1:s(Nz-k);
    j=1:s(Nz-k+1);
    B(i,i)=inv(H(i,i,Nz-k)-T1(i,j,Nz-k)*B(j,j)*T2(j,i,Nz-k));
end
i=1:s(1);
j=1:s(2);
invA(i,i)=inv(H(i,i,1)-T1(i,j,1)*B(j,j)*T2(j,i,1));
