# How do I write this matrix?

The following code gives 20 data as output.

How can I make a 5*4 matrix by that data list?

• Check out Table, and don't forget to capitalize Sin and Cos. – Chris K Nov 4 '18 at 15:11
• Please post code in code blocks in the future. This is not copyable. I think this will answer all your questions: Why avoid For – Szabolcs Nov 4 '18 at 15:23
• It is edited @Szabolcs – a b Nov 4 '18 at 15:42
• Hi a-b, when Szabolcs asks for code, he means text that can be copy-pasted. The only way we can fix problems is if we can reproduce them! – bill s Nov 4 '18 at 15:48
• Please post the code as text (not an image). – Peter Mortensen Nov 4 '18 at 20:58

Here is a starting point without the For loops:

Clear@f;
f[i_, j_] /; OddQ[j] := c[i, j];
f[i_, j_] /; EvenQ[j] := s[i, j];

n1 = 2;
res = Table[f[i, j], {i, -n1, n1}, {j, 1, 2*n1}];

(* Note MatrixForm is for presentation, not for computations *)
res // MatrixForm


You can then enter your definition of c and s

• Oh please, leave away MatrixForm. It is the cause for so many desperate questions on this forum... (still +1). – Henrik Schumacher Nov 4 '18 at 16:07
• Good point! I added a comment above to separate the calculated result from the presentation. – FredrikD Nov 4 '18 at 16:09
n = 2;
Table[
If[OddQ[j],
Cos[2. Pi i j/(2 n + 1)],
Sin[2. Pi i j/(2 n + 1)]
],
{i, -n, n}, {j, 1, 2 n}
]

• +1 Or slightly shorter Table[If[OddQ[j], Cos, Sin][2. Pi i j/(2 n + 1)], {i, -n, n}, {j, 2 n}] – Bob Hanlon Nov 4 '18 at 18:19