See my following example:
In[627]:= getTrMat//ClearAll;
getTrMat[ns_]:=Block[{dim=Sqrt[Length[ns[[1]]]],x},
If[ Length[ns]==1,
Partition[ns//First,dim],
Partition[Sum[x[i] ns[[i]], {i, Length[ns]}],dim]
]
]
In[639]:= ns ={{3/4, 5/8, 5/8, 0, 5/8, 3/4, 5/8, -(1/8), 5/8, 5/8, 3/4, -(1/8), 0,
0, 0, 1}};
getTrMat[ns]
Out[640]= {{3/4, 5/8, 5/8, 0}, {5/8, 3/4, 5/8, -(1/8)}, {5/8, 5/8, 3/
4, -(1/8)}, {0, 0, 0, 1}}
In the above example, should the index variable i also be defined as local variables or not? More specifically, should I use which of the following forms at the beginning of the Block command?
Block[{dim=Sqrt[Length[ns[[1]]]], x},
Block[{dim=Sqrt[Length[ns[[1]]]], x, i},
Regards, Zhao