4
$\begingroup$

How do i create 15x2 matrix with 2x2 random integer elements?

My code only returned identical 2x2 elements: This is what i get when i tried to do that.

$\endgroup$
4
  • 3
    $\begingroup$ Please do not post images of code, but post code as text with markdown formatting. $\endgroup$
    – m_goldberg
    Commented Jun 23, 2014 at 13:58
  • $\begingroup$ want to Create 2*2 matrix consist of 2 rows and 15 columns with random integers up to 15. $\endgroup$ Commented Jun 23, 2014 at 14:01
  • $\begingroup$ Not a 15x2 matrix with each element being a 2x2 random integer matrix? That is what your example looks like. $\endgroup$
    – Yves Klett
    Commented Jun 23, 2014 at 14:01
  • $\begingroup$ That is right.. $\endgroup$ Commented Jun 23, 2014 at 14:03

3 Answers 3

4
$\begingroup$

You don't really want to use ConstantArray which always populates the matrix with its first argument repeated as many times as necessary. That first argument is only evaluated once which explains your result. To get what you want, use RandomInteger directly. It can build matrices.

SeedRandom@42;
RandomInteger[14, {2, 15, 2, 2}] // MatrixForm

matrix

$\endgroup$
0
$\begingroup$

An inferior alternative to the direct call to RandomInteger, but quite close to your original idea:

Table[RandomInteger[{0, 100}, {2, 2}], {2}, {15}] // MatrixForm

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ This is good.. Thanks $\endgroup$ Commented Jun 23, 2014 at 14:05
  • $\begingroup$ Please note that @m_goldbergs answers is the way to go in terms of efficiency and speed. $\endgroup$
    – Yves Klett
    Commented Jun 23, 2014 at 14:08
0
$\begingroup$

Is this what you are looking for?

Table[MatrixForm[RandomInteger[14, {2, 2}]], {i, 2}, {j,15}] // MatrixForm

$\endgroup$
2
  • $\begingroup$ Thanks... Now how can i find the determinant of this matrix.. $\endgroup$ Commented Jun 23, 2014 at 14:55
  • $\begingroup$ Further calculations with nested MatrixForm elements will be difficult, though. $\endgroup$
    – Yves Klett
    Commented Jun 23, 2014 at 16:28

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.