Question: Code for a Recurrence Matrix

I want to find following NxN matrix P                                           (N=2^k.M where k and M are a positive integers)  

My Code Try: question.mw

restart:
with(LinearAlgebra):
interface(rtablesize=20):
k:=2:
M:=4:
N:=2^k*M: 
for i from 1 to M do
S:= (sqrt(2)/2^k)*Matrix(M,M, (i,j)-> `if`(`and`(i::odd,j=1) ,-1/(i*(i-2)),0)):   
end do:
C:= (1/2^k)*BandMatrix( [ [ seq(-1/(2*sqrt(2)*(i-1)*(i-3)), i=4..M)], [ 1, seq(0*i,i=1..M-1) ],[ seq(4/2*(i-3),i=2..M)]
                ]
              ); #I think the matrix C is not same in the question
     
Gen:=proc(K::posint,A,B)
  Matrix(scan=triangular[upper],[seq([A,seq(B,i=j..2^(K)-1)],j=1..2^(K))]);
end proc: 
P:=Gen(k,C,S);

question.mw

Please Wait...