Generate N random numbers between A and B, sum up to X with special condition

johnmpl

Board Regular
Joined
Jun 14, 2013
Messages
237
Office Version
  1. 365
Platform
  1. Windows
Hi to all!


I bring you a challenge to do without the help of macros or Excel tools (like Solver). The idea is to use only Excel formulation, and, if possible, use the same formulation for the entire matrix.


What is needed is to be able to generate a square matrix n x n that results in sum of each of its columns some specific values ​​defined by a given resultant vector.


There are some conditions (restrictions) that must be met:


1. Each value of the matrix must be between 0 and 1, including the extremes (it can be 0 and / or 1 the result).
2. The values ​​of the main diagonal must always be 0.
f1c1, f2c2, ..., fncn = 0
3. The sum of the opposite values ​​between row and column must always be 1. For example
f2c1 + f1c2 = 1
f3c1 + f1c3 = 1
...
f3c2 + f2c3 = 1
f4c2 + f2c4 = 1
...
and so on.
4. Values ​​should not be negative (clearly this condition is only for clarity, due to condition 1 that includes it).


Possibly several solutions are found to the problem, but just one solution is needed that satisfies all the given conditions. The example given below satisfies all restrictions.

n = 7

0,00,30,30,30,40,00,1
0,70,00,50,50,60,10,2
0,70,50,00,50,60,10,2
0,70,50,50,00,40,20,3
0,60,40,40,60,00,00,1
1,00,90,90,81,00,00,7
0,90,80,80,70,90,30,0

<colgroup><col span="7"></colgroup><tbody>
</tbody>

Given Vector:
4,63,43,43,43,90,71,6

<tbody>
</tbody>


Any help will be appreciated. Blessings!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Maybe I'm missing something but surely all you need to do is define your main diagonal as zeroes then enter =RAND() in all the cells below the main diagonal. Then in each of the cells above the main diagonal just enter =1-<the cell="" corresponding="">(the corresponding cell) eg in B1 enter =1-A2</the>
 
Last edited:
Upvote 0
Thx gsbelbin for your answer

No...

I know that RAND() function give a random number between 0 and 1... but this numbers must give a specified sum by column, depends on the given vector:

In the above example:
0.0 + 0.7 + 0.7 + 0.7 + 0.6 + 1.0 + 0.9 = 4.6
0.3 + 0.0 + 0.5 + 0.5 + 0.4 + 0.9 + 0.8 = 3.4
... and so on.

And the random numbers must have some conditions:

1. Each value of the matrix must be between 0 and 1, including the extremes (it can be 0 and / or 1 the result).
2. The values ​​of the main diagonal must always be 0.
f1c1, f2c2, ..., fncn = 0
3. The sum of the opposite values ​​between row and column must always be 1. For example
f2c1 + f1c2 = 1
f3c1 + f1c3 = 1
...
f3c2 + f2c3 = 1
f4c2 + f2c4 = 1
...
and so on.
4. Values ​​should not be negative (clearly this condition is only for clarity, due to condition 1 that includes it).

Blessings!
 
Upvote 0
Where does "random" factor into this? It seems like your four conditions would mean the matrix values must by definition be non-random.
 
Upvote 0
Hi, rlv01! thx for your answer.

No... there is no factor. Is "random" because you could get any value between 0 and 1 (with several decimals, if you needed). But is "random with conditions", because you have to take care about some conditions explained above. There could be multiple answer, but just with one is enough. Blessings!
 
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,674
Members
448,977
Latest member
moonlight6

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top