I need to create a block tridiagonal matrix in Scilab. More explicitly I would like to set up a M^2 X M^2 matrix of the format:
B C 0 ... 0 0
D B C 0 ... 0
0 D B C ... 0
0 ... ... ... ...
0 0 ... D B C
0 0 0 ... D B
where B,C and D are M X M matrices.
I know how to create a block diagonal matrix with help of the "sysdiag" function but I haven't found any reference for easily creating a block tridiagonal one.
By the way given the matrices B,C and D I know how to create the matrix above.
auxA = sysdiag(B,B);
auxC = C;
auxD = D;
for i=1:2*M-1
auxA = sysdiag(auxA,B);
auxC = sysdiag(auxC,C);
auxD = sysdiag(auxD,D);
end
A = auxA + [zeros((2*M+1)^2 -(2*M+1),2*M+1) auxC ;zeros(2*M+1,2*M+1) zeros(2*M+1,(2*M+1)^2 -(2*M+1)) ] + [zeros(2*M+1,(2*M+1)^2 -(2*M+1)) zeros(2*M+1,2*M+1); auxD zeros((2*M+1)^2 -(2*M+1),2*M+1)];
I would still like to knwo if there is a function that does it directly in Scilab, Matlab or R. Could someone help me with that please?
All advices are appreciated.
Many thanks