Construct a matrix row by row with some rules on elements
I want to construct a matrix in which the first rows, along with the last ones, are peculiar, being the last ones the inverted forms of the first ones, while the central rows have the same form, just with the nonzero part shifted right by proceeding from one row to the next one. In Matlab or Octave I would have written something like:
# begin Matlab equivalent code for matrix
# A=zeros(nn+1)
# A(1,1:4)=[m11 m12 m13 m14]
# A(2,1:5)=[m12 m22 m23 m24 m25]
# A(3,1:6)=[m13 m23 m33 m34 m35 m36]
# A(4,1:7)=[m14 m24 m34 m33 m34 m35 m36]
# A(5,2:8)=[m25 m35 m34 m33 m34 m35 m36]
# for i=6:nn-4
# A(i,i-3:i+3)=[m36 m35 m34 m33 m34 m35 m36]
# end
# A(nn-3,nn-6:nn)=A(5,8:-1:2)
# A(nn-2,nn-5:nn+1)=A(4,7:-1:1)
# A(nn-1,nn-4:nn+1)=A(3,6:-1:1)
# A(nn,nn-3:nn+1)=A(2,5:-1:1)
# A(nn+1,nn-2:nn+1)=A(1,4:-1:1)
# end Matlab equivalent code for matrix
Although I was able to construct it also in Sage with a fixed nn=10:
aa=10
nn=10
vecordinv_matrix=matrix([[0,0,0,0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,1,0,0], \
[0,0,0,0,0,0,0,1,0,0,0],[0,0,0,0,0,0,1,0,0,0,0],[0,0,0,0,0,1,0,0,0,0,0], \
[0,0,0,0,1,0,0,0,0,0,0],[0,0,0,1,0,0,0,0,0,0,0],[0,0,1,0,0,0,0,0,0,0,0], \
[0,1,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0,0]])
mv1=vector((N(m11_tot(aa,nn)),N(m12_tot(aa,nn)),N(m13_tot(aa,nn)),N(m14_tot(aa,nn)), \
0,0,0,0,0,0,0))
mv2=vector((N(m12_tot(aa,nn)),N(m22_tot(aa,nn)),N(m23_tot(aa,nn)),N(m24_tot(aa,nn)), \
N(m25_tot(aa,nn)),0,0,0,0,0,0))
mv3=vector((N(m13_tot(aa,nn)),N(m23_tot(aa,nn)),N(m33_tot(aa,nn)),N(m34_tot(aa,nn)), \
N(m35_tot(aa,nn)),N(m36_tot(aa,nn)),0,0,0,0,0))
mv4=vector((N(m14_tot(aa,nn)),N(m24_tot(aa,nn)),N(m34_tot(aa,nn)),N(m33_tot(aa,nn)), \
N(m34_tot(aa,nn)),N(m35_tot(aa,nn)),N(m36_tot(aa,nn)),0,0,0,0))
mv5=vector((0,N(m25_tot(aa,nn)),N(m35_tot(aa,nn)),N(m34_tot(aa,nn)),N(m33_tot(aa,nn)), \
N(m34_tot(aa,nn)),N(m35_tot(aa,nn)),N(m36_tot(aa,nn)),0,0,0))
mv6=vector((0,0,N(m36_tot(aa,nn)),N(m35_tot(aa ...