2
$\begingroup$

The following code gives 20 data as output.

Enter image description here

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

$\endgroup$
  • 2
    $\begingroup$ Check out Table, and don't forget to capitalize Sin and Cos. $\endgroup$ – Chris K Nov 4 '18 at 15:11
  • 4
    $\begingroup$ Please post code in code blocks in the future. This is not copyable. I think this will answer all your questions: Why avoid For $\endgroup$ – Szabolcs Nov 4 '18 at 15:23
  • $\begingroup$ It is edited @Szabolcs $\endgroup$ – a b Nov 4 '18 at 15:42
  • 3
    $\begingroup$ 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! $\endgroup$ – bill s Nov 4 '18 at 15:48
  • $\begingroup$ Please post the code as text (not an image). $\endgroup$ – Peter Mortensen Nov 4 '18 at 20:58
5
$\begingroup$

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

enter image description here

You can then enter your definition of c and s

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ Oh please, leave away MatrixForm. It is the cause for so many desperate questions on this forum... (still +1). $\endgroup$ – Henrik Schumacher Nov 4 '18 at 16:07
  • $\begingroup$ Good point! I added a comment above to separate the calculated result from the presentation. $\endgroup$ – FredrikD Nov 4 '18 at 16:09
4
$\begingroup$
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}
 ]
| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ +1 Or slightly shorter Table[If[OddQ[j], Cos, Sin][2. Pi i j/(2 n + 1)], {i, -n, n}, {j, 2 n}] $\endgroup$ – Bob Hanlon Nov 4 '18 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.