0

I tried to generate a population according to their probability into a list, but the result always gives me the original null list. Cannot figure out why.

bmax[θw_] := (1.14*10^9)/Sin[θw/2]^(9/7);
db = 10^-5;
Pb[θw_, b_] := (2 b db)/bmax[θw]^2;        
a0[θw_, b_] := (3.69*10^12)/((2.5*10^63)/(Sin[θw/2]^7 b^7)-Sin[θw/2]^2); 
a0sim = {0};
n = 10^5;
m = 0;
While[m < n, {θw = π Random[];
              b = bmax[θw] Random[];
              If[Random[] <= Pb[θw, b]*10^13, 
                 {Append[a0sim, a0[θw, b]], m++}]
             }
     ]
a0sim

Output was {0}.

Thanks for helping out!

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371

1 Answers1

1

Append returns the modified list. AppendTo update the list (resets). So using AppendTo works

bmax[θw_] := (1.14*10^9)/Sin[θw/2]^(9/7);
db = 10^-5;
Pb[θw_, b_] := (2 b db)/bmax[θw]^2;
a0[θw_, 
   b_] := (3.69*10^12)/((2.5*10^63)/(Sin[θw/2]^7 b^7) - 
     Sin[θw/2]^2);
a0sim = {0};
n = 10;
m = 0;
While[m < n, {θw = π Random[];
   b = bmax[θw] Random[];
   If[Random[] <= 
     Pb[θw, b]*10^13, {AppendTo[a0sim, a0[θw, b]], 
     m++}]}];

Mathematica graphics

To use Append need to overwrite the list,

    {a0sim = Append[a0sim, a0[θw, b]], m++}]}
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
Nasser
  • 143,286
  • 11
  • 154
  • 359