array(4*4) containing random elements having first row sum= 7 and column 4 element sum = 7.

1 view (last 30 days)
each element of matrix should be in the range 0 t0 7 integer only. other constraints i want this matrix to follow are-
1. diagonal elements=0
2. first column sum=0
3. row four sum =0
4. sum of elements of row 2= sum of elements of column 2
5. sum of elements of row 3= sum of elements of column 3
  7 Comments
Adam
Adam on 20 Aug 2014
Yes, looking at it more carefully (I got thrown off by having read what I'm sure was another question by you that had what looked like impossible constraints in a similar format!) the constraints are probably not impossible though whether you could call the numbers that would be generated to fit such constraints as "random" is debatable!
Roger Stafford
Roger Stafford on 20 Aug 2014
I just worked a similar problem for Reshdev at Answers thread #151552. You people ought to communicate.

Sign in to comment.

Answers (1)

Jan
Jan on 20 Aug 2014
So you mean a matrix of the form:
[0 a c e
0 0 d f
0 b 0 g
0 0 0 0]
This means, that there are 8^7 possible combinations, which are only 2'097'152. You can simply run a brute force attack to check all possibilities, if they match you conditions.
  2 Comments
Image Analyst
Image Analyst on 20 Aug 2014
I like it (+1 vote). Sometimes the brute force way is a lot simpler than some fancy hard-to-understand way. In my simple program of 7 nested for loops, and if statement and counter, I found 16640 matrices that fulfill the requirements. Took 8.9 seconds.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!