This code should return in the variables: B_mtrx_a, C_mtrx_a, a_; a "history" of calculations of matrix B, C and vector a. Observe the command window to show the calculations for each iteration of the for loop.
im=1i; %Imaginary part
% You should modify these variables:
Z = [1;2];
k = [1;2];
X = [1;2];
V = ones(2);
T = ones(2);
% Definition of the functions:
B = @(x)([1 1; im*Z(x,1) -im*Z(x,1)]);
C = @(x)([exp(im*k(x,1)*X(x,1)) 0; 0 exp(-im*k(x,1)*X(x,1))]);
layers = 2;
%pre-allocation, to save the history of calculations.