0
$\begingroup$

I have the following function definition:

P[t_] := 
  P[t] =  P[t - 1] + μ*ED[t - 1] + RandomVariate[NormalDistribution[0, 0.03]];

I want to evaluate P 6000 times and I want to get the same 6000 iterations of the random variable. So I basically know how to get the same 6000 iterations, but I don't know how to create a list so I can use these values in my equation.

I tried it in a simpler way with

a = SeedRandom[5]; 
Table[RandomVariate[NormalDistribution[0, 0.03]], {3}];
b = {1, 2, 3};
a + b

And the output was

{1 + Null, 2 + Null, 3 + Null}

So how can I sum up the numbers resulting from SeedRandom with other numbers?

$\endgroup$
4
  • 1
    $\begingroup$ You never assign your Table to a variable name in your "simpler" way. $\endgroup$ Jan 11, 2018 at 19:14
  • 1
    $\begingroup$ Probably a = should be in the row following SeedRandom. SeedRandom returns Null as it merely sets the seed for pseudorandom number generation. $\endgroup$ Jan 11, 2018 at 19:33
  • $\begingroup$ You don't have an equation; you have a memoized definition of a recursive function. $\endgroup$
    – m_goldberg
    Jan 11, 2018 at 19:37
  • $\begingroup$ note for your simpler case (probably what you really want) you don't even need Table since RandomVariate takes a n argument to generate a list. $\endgroup$
    – george2079
    Jan 11, 2018 at 21:30

2 Answers 2

1
$\begingroup$

Since you are memoizing the values of P[i], you don't need to use SeedRandom at all. Consider,

P[0] = 1;
P[t_] := P[t] = P[t - 1] + RandomVariate[NormalDistribution[0, 0.03]]

Do[P[t], {t, 5}]
Table[P[t], {t, 5}]

{1.0187, 0.982789, 0.974296, 0.9285, 0.931482}

The call to Table didn't run the function P; it just retrieved the memoized values. Repeating the call

Table[P[t], {t, 5}]

{1.0187, 0.982789, 0.974296, 0.9285, 0.931482}

gives the same result.

$\endgroup$
1
  • 1
    $\begingroup$ you need SeedRandom if you want the same sequence again after a kernel restart though. $\endgroup$
    – george2079
    Jan 11, 2018 at 21:27
0
$\begingroup$

in direct form your recursive function looks like this I think:

  p = P[0] + u Accumulate[Table[ED[i], {i, 0, n - 1}]] +
         Accumulate[RandomVariate[NormalDistribution[0, 0.03], n]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.