Hi,
I have a requirement and a solution but I do not like it (and therefore I look for an improvement)!
The requirement is, that a have to split a number (here: 1) randomly in several parts (here: 4) and the sum of all parts have to be the initial value.
e.g.:
1 is splitted into 0.2 + 0.3 + 0.4 + 0.1
in the next run 1 is splitted into 0.3 + 0.3 + 0.2 + 0.2
and so on
The idea I came up was:
1) I use 3 (because I need 4 parts) random variables between 0 and 1 (1 because it is the number I have to split)
2) I sort the 3 random numbers (let me name it r1, r2, r3)
3) I calculate the differences between the numbers, and the differences are my final results
r1 - 0 (0 is my lower limit)
r2 - r1
r3 - r2
1 - r3 (1 is my upper limit)
What I do not like is:
- sorting is hard in Vensim PLE Plus
- it is a lot of work to extend it to more parts
Any idea how to do this job in a better / simpler way is appreciated!
Regards,
jmu
Splitting a number
-
- Super Administrator
- Posts: 4838
- Joined: Wed Mar 05, 2003 3:10 am
Re: Splitting a number
How about something like
This is much easier when using subscripts, but those are not in PLE+.
Code: Select all
R1 = RANDOM UNIFORM()
R2 = RANDOM UNIFORM()
R3 = RANDOM UNIFORM()
R4 = RANDOM UNIFORM()
TOTAL RANDOM = R1 + R2 + R3 + R4
R1 share = R1 / TOTAL RANDOM
R2 share = R2 / TOTAL RANDOM
R3 share = R3 / TOTAL RANDOM
R4 share = R4 / TOTAL RANDOM
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Splitting a number
Thanks for the help - and it is so easy !