# Writing fully coupled recursion equations as one generic equation

The following pair of coupled recursion equations represents movement between population 1 (x[1, t]) and population 2 (x[2, t]) over time (t).

x[1, t_] := x[1, t] = (1 - m) x[1, t - 1] + m x[2, t - 1]
x[2, t_] := x[2, t] = (1 - m) x[2, t - 1] + m x[1, t - 1]

x[1, 0] := 1
x[2, 0] := 0


I want to write the coupled recursion equations as one line instead of two (similar to below) where the first argument describes the population number. However, in the body of the equation, I don't know how to tell Mathematica that if k = 1, l should equal 2, and if k = 2, l should equal 1.

x[k_,t_] := x[k,t] = (1-m) x[k, t - 1] + m x[l, t - 1]

x[1, 0] := 1
x[2, 0] := 0


Is this possible in the context of a recursion equation? Maybe there is a way to define an argument that can only take on two values?

• Something like x[k_, t_] := x[k, t] = (1 - m) x[k, t - 1] + m x[3 - k, t - 1] or x[k_, t_] := x[k, t] = (1 - m) x[k, t - 1] + m x[If[k == 2, 1, 2], t - 1]. – march Sep 16 '16 at 23:02
• The latter is clever and appears to work! It does add a little to the evaluation time but maybe that can't be helped. – biologyUser Sep 16 '16 at 23:12
• Doesn't the first one work? I would expect it to be faster. – march Sep 16 '16 at 23:14
• Oh wait! That is faster! I was worried Mathematica would think it should iterate over k also if there was k - stuff but stuff - k seems to work. – biologyUser Sep 16 '16 at 23:26

A simpler way to write this is

M = {{1 - m, m}, {m, 1 - m}};
X[t_] := X[t] = M.X[t - 1]
X := {1, 0}


Alternatively, you can recognise this as a matrix power, applied to a constant vector

X1[t_] := MatrixPower[M, t, {1, 0}]


In this case, it can be evaluated symbolically

X1[t]
(* {1/2 + 1/2 (1 - 2 m)^t, 1/2 - 1/2 (1 - 2 m)^t} *)

• An added advantage of this approach is seeing your model as a matrix population model, for which much theory has been developed (e.g. Caswell 2000). – Chris K Sep 17 '16 at 14:51