如何从列表中选择值。 Mathematica

时间:2019-05-08 15:09:53

标签: statistics wolfram-mathematica

我有此代码:

    x = {1, 2, 3, 4, 5}; p = {0.5, 0.3, 0.1, 0.06, 0.04};
Do[
 n = RandomVariate[PoissonDistribution[30]]; M = Table[0, {n}];
 Do[
  U = RandomReal[]; i = 1;
  While[U > Sum[p[[j]], {j, 1, i}], i = i + 1];
  X = x[[i]]; M[[j]] = X;
  , {j, 1, n}];
 Daytotal[k] = M
 , {k, 1, 365}]
W = Table[Total[Daytotal[m]], {m, 1, 365}];
N[Mean[W]]
Histogram[W, Automatic, "PDF"]

我想从 W 中选择大于80的值。我已经尝试使用命令While尝试了一切,但是找不到结果。

1 个答案:

答案 0 :(得分:1)

任何一个

greaterthan80={};
i=1;
While[i<=365,
  If[W[[i]]>80,
    AppendTo[greaterthan80,W[[i]]]
  ];
  i++
];
greaterthan80

isitgreater[x_]:=x>80;
greaterthan80=Select[W,isitgreater]

或者只是

greaterthan80=Select[W,#>80&]