# Constructing a particular Toeplitz matrix with a certain rule

I want to construct a Toeplitz matrix in Mathematica. Usually it is done in Mathematica using the following command:

ToeplitzMatrix[{a,b,...},{a,y,...}]


I want to have the first and the second list like {a,b,...} and {a,y,...} above to each contain N elements for a given number N (say 5 or 6; I want to keep the option of changing it). I want a=0. From b onwards I want to have (-1)^n nx (starting with n=1) and from y onwards -(-1)^n nx alternatively.

I am quite new to all the powers of Mathematica. So some help will be greatly appreciated.

tf[nn_] := With[{n = Range[0, nn]}, ToeplitzMatrix[(-1)^n n x, -(-1)^n n x]]


For the question in the comment:

tf2[nn_] :=
With[{n = Range[0, nn]},
Module[{expr = (-1)^n Cot@(n x)}, expr[] = 0; ToeplitzMatrix[expr, -expr]]]

tf3[nn_] :=
With[{n = Range@nn},
With[{expr = Join[{0}, (-1)^n Cot@(n x)]}, ToeplitzMatrix[expr, -expr]]]

• Sorry, but it says: – Student Jan 28 '16 at 14:39
• "Objects of unequal length in {1,-1,1,-1,1}\ {0,1,2,3,4}\ {[Pi]/12,\ [Pi]/6,[Pi]/4,[Pi]/3,(5\[Pi])/12,[Pi]/2,(7\[Pi])/12,(2\[Pi])/3,\ (3\[Pi])/4,(5\[Pi])/6,(11\[Pi])/12,[Pi],(13\[Pi])/12,(7\[Pi])/6,\ (5\[Pi])/4,(4\[Pi])/3,(17\[Pi])/12,(3\[Pi])/2,(19\[Pi])/12,(5\[\ Pi])/3,(7\[Pi])/4,(11\[Pi])/6,(23\[Pi])/12,2\ [Pi]} cannot be \ combined" – Student Jan 28 '16 at 14:39
• Also, here the first element 0 is obtained just by putting 0 for n in (-1)^n nx. But what if I have 0 for the diagonals and say (-1)^n cot(nx), so that I really need to put a second rule for the diagonals? – Student Jan 28 '16 at 14:41
• @Student You forgot to Clear[x] – xzczd Jan 28 '16 at 14:41
• Sorry, it is working for what you said. But for the other one I mentioned, I can't do e.g. tf[nn_] := With[{n = Range[0, nn]}, ToeplitzMatrix[{0,(-1)^n Cot[n x]}, {0,-(-1)^n Cot[n x]}]]. – Student Jan 28 '16 at 14:47