Message Boards Message Boards

0
|
2757 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Make a simulation using NestWhileList- iterating arrays

Posted 4 years ago

Hi, I try to simulate using NestWhileList. In each iteration a list of three elements is generated. The test is a condition on one of the elements.

NestWhileList[{RandomReal[
    ExponentialDistribution[\[Lambda] + 
      If[#[[2]] > 0, \[Mu], 0]]], #[[2]] + 
    2 RandomInteger[
      BernoulliDistribution[\[Lambda]/(\[Lambda] + 
        If[#[[2]] > 0, \[Mu], 0])]] - 
    1, #[[1]] + #[[3]]} &, {RandomReal[
   ExponentialDistribution[\[Lambda]]], 0, 0}, #[[3]] & < T]

Yet, it does nothing, in the meaning that the test fails right away and the output is

{{1.8569, 0, 0}}

It has no relation to the random ingredients, because I tried the same idea with fixed functions and the outcome is the same. The test does not read from the array the way I want it?

Thanks, Yoav

POSTED BY: Yoav Kerner
2 Replies
Posted 4 years ago

Thanks Rohit

The values were predefined. The mistake was stupid. I put the "&" not after the "T" in the test.
I looked at your example and realized it. Many thanks.

POSTED BY: Yoav Kerner
Posted 4 years ago

Hi Yoav,

What are the values of λ, μ and T? I would start with a simpler example that works and adapt it to your problem. e.g.

NestWhileList[If[#[[1]] < 2, #*2, #*3] &, {1, 2, 3}, #[[3]] < 12 &]
(* {{1, 2, 3}, {2, 4, 6}, {6, 12, 18}} *)
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract