how to generate all possible combinations of a 14x10 matrix containing only 1's and 0's

前端 未结 11 995
悲&欢浪女
悲&欢浪女 2021-01-23 23:32

I\'m working on a problem and one solution would require an input of every 14x10 matrix that is possible to be made up of 1\'s and 0\'s... how can I generate these so that I can

11条回答
  •  醉梦人生
    2021-01-24 00:04

    This is absolutely impossible! The number of possible matrices is 2140, which is around 1.4e42. However, consider the following...

    • If you were to generate two 14-by-10 matrices at random, the odds that they would be the same are 1 in 1.4e42.
    • If you were to generate 1 billion unique 14-by-10 matrices, then the odds that the next one you generate would be the same as one of those would still be exceedingly slim: 1 in 1.4e33.
    • The default random number stream in MATLAB uses a Mersenne twister algorithm that has a period of 219936-1. Therefore, the random number generator shouldn't start repeating itself any time this eon.

    Your approach should be thus:

    • Find a computer no one ever wants to use again.
    • Give it as much storage space as possible to save your results.
    • Install MATLAB on it and fire it up.
    • Start computing matrices at random like so:

      while true
        newMatrix = randi([0 1],14,10);
        %# Process the matrix and output your results to disk
      end
      
    • Walk away

    Since there are so many combinations, you don't have to compare newMatrix with any of the previous matrices since the length of time before a repeat is likely to occur is astronomically large. Your processing is more likely to stop due to other reasons first, such as (in order of likely occurrence):

    • You run out of disk space to store your results.
    • There's a power outage.
    • Your computer suffers a fatal hardware failure.
    • You pass away.
    • The Earth passes away.
    • The Universe dies a slow heat death.

    NOTE: Although I injected some humor into the above answer, I think I have illustrated one useful alternative. If you simply want to sample a small subset of the possible combinations (where even 1 billion could be considered "small" due to the sheer number of combinations) then you don't have to go through the extra time- and memory-consuming steps of saving all of the matrices you've already processed and comparing new ones to it to make sure you aren't repeating matrices. Since the odds of repeating a combination are so low, you could safely do this:

    for iLoop = 1:whateverBigNumberYouWant
      newMatrix = randi([0 1],14,10);  %# Generate a new matrix
      %# Process the matrix and save your results
    end
    

提交回复
热议问题