I have the following recurrence relation:

```
\begin{equation}
A[n]=f_A[n-1] A[n-1] + f_B[n-1]B[n-1], \\
B[n]=g_A[n-1] A[n-1] + g_B[n-1]B[n-1],
\end{equation}
```

where $f_{A/B}$ and $g_{A/B}$ are known complex functions that vary at each step $n$. I would like to know $A[n+i]$ in terms of $A[n]$ and $B[n]$, for some positive integer $i$.

I have taken the obvious approach of putting the coefficients into a matrix $X[n]=\mathcal{M}_{n-1}X[n-1]$ where

```
\begin{equation}
\mathcal{M}_n =
\begin{pmatrix}
f_A[n] & f_B[n] \\
g_A[n] & g_B[n] \\
\end{pmatrix}.
\end{equation}
```

With my functions $f$ and $g$ (I can put them in later if it matters) the determinant of $\mathcal{M}_n$ is non-zero, so it has an inverse and should be able to be diagonalized --- the eigenvalues and eigenvectors are of course trivial to find. If $f$ and $g$ were constant, this would just be a matter of diagonalizing $\mathcal{M}$ and finding the $i$-th power. However, the basis which diagonalizes $\mathcal{M}_n$ changes depending on when $f_B$ and $g_A$ are zero. OK, so I attempt to break my problem into pieces where I can take $j$ steps in one basis before shifting to another. After I do this, however, I'm not finding it straightforward how to express my desired result $A[n+i]=\mathcal{F}(A[n]+B[n])$. Furthermore, in an effort to be as general as possible, I'm trying to consider general functions $f_{A/B}$ and $g_{A/B}$ that may be zero at known, but arbitrary steps $n$, which compounds my difficulties.

I'm a physicist and don't run into recurrence relations everyday. Also, I'm finding that my undergraduate linear algebra tools have unfortunately rusted a bit. Help?