Advertisement
Guest User

Untitled

a guest
Dec 27th, 2010
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. Lubos Motl
  2. Dear Steve, of course that the answer to this latest problem will be 43% or so, the program is attached below. But it's because what you're doing is borderline cheating. You want to create the impression that there are 100 years and potentially 400 births in those four families. However, the typical run will only produce 5-10 children. So in every single run, the number of children will fail to be large.
  3.  
  4. This latest problem has nothing to do with a population. It is a group of 5-10 people that goes extinct within 2 years or so.
  5. Yesterday, 03:40:11 – Flag – Like – Reply
  6.  
  7. Lubos Motl
  8. Here is the program, I needed 5 minutes to write it and a few seconds to run it. Input:
  9.  
  10.  
  11.  
  12. sumOfFractions = 0; runs = 1000; years = 100;
  13. For[run = 1, run <= runs, run++,
  14.  
  15. stillproducing = {1, 1, 1, 1};
  16. girlsboys = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
  17. (* 0 is boy and 1 is girl *)
  18.  
  19. For[year = 1, year <= years, year++,
  20. For[family = 1, family <= 4, family++,
  21.  
  22. randomsex = RandomInteger[];
  23.  
  24. girlsboys[[family, randomsex + 1]] =
  25. girlsboys[[family, randomsex + 1]] + stillproducing[[family]]
  26. ;
  27. stillproducing[[family]] = stillproducing[[family]]*randomsex;
  28. ];
  29. ]; (* Print[MatrixForm[girlsboys]]; *)
  30. fraction = Total[girlsboys[[All, 2]]]/Total[Flatten[girlsboys]];
  31. sumOfFractions = sumOfFractions + fraction;
  32. ];
  33. overallGirlPercentage = sumOfFractions/runs
  34. N[overallGirlPercentage]
  35.  
  36.  
  37. Output:
  38.  
  39. 12803786239/29099070000
  40. 0.44000672
  41.  
  42. This has nothing to do with the original problem because there's no "population" here.
  43. Yesterday, 03:41:28 – Flag – Like – Reply
  44.  
  45. Lubos Motl
  46. If you correctly calculated the weighted average over the runs, with weights given by the total number of children in the run, you get 50%:
  47.  
  48.  
  49.  
  50. sumOfFractions = 0; runs = 1000; years = 100;
  51. totalweights = 0;
  52.  
  53. For[run = 1, run <= runs, run++,
  54.  
  55. stillproducing = {1, 1, 1, 1};
  56. girlsboys = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
  57. (* 0 is boy and 1 is girl *)
  58.  
  59. For[year = 1, year <= years, year++,
  60. For[family = 1, family <= 4, family++,
  61.  
  62. randomsex = RandomInteger[];
  63.  
  64. girlsboys[[family, randomsex + 1]] =
  65. girlsboys[[family, randomsex + 1]] + stillproducing[[family]]
  66. ;
  67. stillproducing[[family]] = stillproducing[[family]]*randomsex;
  68. ];
  69. ]; (* Print[MatrixForm[girlsboys]]; *)
  70. weight = Total[Flatten[girlsboys]];
  71. fraction = Total[girlsboys[[All, 2]]]/weight*weight;
  72. sumOfFractions = sumOfFractions + fraction;
  73. totalweights = totalweights + Total[Flatten[girlsboys]];
  74. ];
  75. overallGirlPercentage = sumOfFractions/totalweights
  76. N[overallGirlPercentage]
  77.  
  78.  
  79. Output:
  80.  
  81. 519/1019 = 0.5093
  82. With a higher number of runs, you get closer to 50%
  83. Yesterday, 03:46:30 – Flag – Like – Reply
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement