Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
3  
Please do not post images of code, but post code as text with markdown formatting. –  m_goldberg Jun 23 at 13:58
    
want to Create 2*2 matrix consist of 2 rows and 15 columns with random integers up to 15. –  Irah Idebus Jun 23 at 14:01
    
Not a 15x2 matrix with each element being a 2x2 random integer matrix? That is what your example looks like. –  Yves Klett Jun 23 at 14:01
    
That is right.. –  Irah Idebus Jun 23 at 14:03

3 Answers 3

up vote 4 down vote accepted

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

share|improve this answer

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

share|improve this answer
    
This is good.. Thanks –  Irah Idebus Jun 23 at 14:05
    
Please note that @m_goldbergs answers is the way to go in terms of efficiency and speed. –  Yves Klett Jun 23 at 14:08

Is this what you are looking for?

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

share|improve this answer
    
Thanks... Now how can i find the determinant of this matrix.. –  Irah Idebus Jun 23 at 14:55
    
Further calculations with nested MatrixForm elements will be difficult, though. –  Yves Klett Jun 23 at 16:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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