2
$\begingroup$

enter image description here

I am trying to create a Matrix 4x4 with elements from [-1,1], using the commands RandomReal and Table. When I am trying to use the command Table, I destroy my code. Any advice?

$\endgroup$
4
  • $\begingroup$ I don't understand, why do you need to use Table[] ? Apparently your code is working... $\endgroup$
    – Matteo
    Nov 27, 2022 at 23:04
  • 1
    $\begingroup$ community.wolfram.com/groups/-/m/t/2710921 $\endgroup$
    – Bill
    Nov 27, 2022 at 23:25
  • 2
    $\begingroup$ You could also write: Table[RandomReal[{-1, 1}], {i, 4}, {j, 4}] to get the random matrix, though it's not simpler than RandomReal[{-1,1},{4,4}] $\endgroup$
    – bill s
    Nov 27, 2022 at 23:50
  • 1
    $\begingroup$ Please directly post the Mathematica code in the input frame. $\endgroup$
    – cvgmt
    Nov 28, 2022 at 2:16

1 Answer 1

3
$\begingroup$
Clear["Global`*"]

The different methods produce identical results

SeedRandom[1234];

tab1 = Table[RandomReal[{-1, 1}], 4, 4];

SeedRandom[1234];

tab2 = RandomReal[{-1, 1}, {4, 4}];

SeedRandom[1234];

tab3 = Array[RandomReal[{-1, 1}] &, {4, 4}];

tab1 === tab2 === tab3

(* True *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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