I am trying to construct a recursion, g[t]
, where
g[t] = a[t]
ifg[t-1] = 1
g[t] = b[t]
ifg[t-1] = 2
.
Additionally a
and b
are defined as:
a[t_] := If[0 <= RandomReal[] <= 0.94, 1, 2]
b[t_] := If[0 <= RandomReal[] <= 0.9, 2, 1]
So then I want (I've also tried it where I replace a
and b
with their original defintions):
g[t_]:= Piecewise[{{a[t], g[t - 1] = 1}, {b[t], g[t - 1] = 2}}]
g[1] = 1
This, however, is not working.
g[t-1]=1
does not mean is equal to? Therefore, you first two bullet points don't make sense to me, because after the if I expect a true/false. $\endgroup$==
and=
. I suggest we close this Q&A (but I'm still glad I got to write an answer!) $\endgroup$