Splitting a number

Use this forum to post Vensim related questions.
Post Reply
jmu
Member
Posts: 21
Joined: Fri Nov 14, 2008 12:32 pm

Splitting a number

Post by jmu »

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
Administrator
Super Administrator
Posts: 4838
Joined: Wed Mar 05, 2003 3:10 am

Re: Splitting a number

Post by Administrator »

How about something like

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
This is much easier when using subscripts, but those are not in PLE+.
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
jmu
Member
Posts: 21
Joined: Fri Nov 14, 2008 12:32 pm

Re: Splitting a number

Post by jmu »

Thanks for the help - and it is so easy !
Post Reply