%This function calculates the transfer matrix for
%a barrier given the energy of the incoming
%particle (E), the length of the barrier (L) and
%the height of the barrier (V)

function [TM31]=TMbarr(E,L,V)

i=sqrt(-1);
%m=9.11e-31;
%hbar=1.055e-34;
m=1;
hbar=1;

%Calculate the wavevectors in the three regions
k1=sqrt(2*m*E)/hbar;
k2=sqrt(2*m*(E-V))/hbar;
k3=k1;

%Calculate the transfer matrix between
%region 1 and 2 (T21), (at x=0)

M10=[1 1; i*k1 -i*k1]*[exp(i*k1*0) 0; 0 exp(-i*k1*0)];
M20=[1 1; i*k2 -i*k2]*[exp(i*k2*0) 0; 0 exp(-i*k2*0)];
TM21=inv(M20)*M10;


%Calculate the transfer matrix between
%region 2 and 3 (T32) (at x=L)

M2L=[1 1; i*k2 -i*k2]*[exp(i*k2*L) 0; 0 exp(-i*k2*L)];
M3L=[1 1; i*k3 -i*k3]*[exp(i*k3*L) 0; 0 exp(-i*k3*L)];

TM32=inv(M3L)*M2L;

%Calculate the total transfer-matrix for the barrier

TM31=TM32*TM21;

