0
$\begingroup$

This question already has an answer here:

$T(n) = \begin{cases} 2: & n=0\\ 5: & n=1 \\ 2T(n-2) - T(n-1): &n \geq 2 \end{cases}$

I have found a few examples including https://math.stackexchange.com/questions/1316301/if-tn-tn-1-2tn-2 But I am still lost about how to solve this one.

$\endgroup$

marked as duplicate by Evil, Yuval Filmus, David Richerby, adrianN, Rick Decker Sep 28 '17 at 0:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2
$\begingroup$

Here's a general technique on linear recurrences that's useful to know. Observe that:

$$ \begin{bmatrix} T(n) \\ T(n+1) \end{bmatrix} = \begin{bmatrix} 0 & 1 \\ 2 & -1 \end{bmatrix}^{n} \begin{bmatrix} 2 \\ 5 \end{bmatrix}$$

If we can perform an eigendecomposition of $M$:

$$M = Q \Lambda Q^{-1}$$

where $\Lambda$ is a diagonal matrix, then:

$$M^n = Q \Lambda^n Q^{-1}$$

Raising a diagonal matrix to a power is trivial. This gives you a closed form for $M^n$.

In your case:

$$\begin{bmatrix} 0 & 1 \\ 2 & -1 \end{bmatrix} = \begin{bmatrix} -\frac{1}{\sqrt{5}} & \frac{1}{\sqrt{2}} \\ \frac{2}{\sqrt{5}} & \frac{1}{\sqrt{2}} \end{bmatrix} \begin{bmatrix} -2 & 0 \\ 0 & 1 \end{bmatrix} \begin{bmatrix} \frac{-\sqrt{5}}{3} & \frac{\sqrt{5}}{3} \\ \frac{2\sqrt{2}}{3} & \frac{\sqrt{2}}{3} \end{bmatrix}$$

So:

$$ \begin{bmatrix} T(n) \\ T(n+1) \end{bmatrix} = \begin{bmatrix} -\frac{1}{\sqrt{5}} & \frac{1}{\sqrt{2}} \\ \frac{2}{\sqrt{5}} & \frac{1}{\sqrt{2}} \end{bmatrix} \begin{bmatrix} -2 & 0 \\ 0 & 1 \end{bmatrix}^n \begin{bmatrix} \frac{-\sqrt{5}}{3} & \frac{\sqrt{5}}{3} \\ \frac{2\sqrt{2}}{3} & \frac{\sqrt{2}}{3} \end{bmatrix} \begin{bmatrix} 2 \\ 5 \end{bmatrix}$$

Multiplying the matrices together, taking the top row, and simplifying gives:

$$T(n) = 3 - (-2)^n$$

It's a lot of work (if you don't have a computer algebra system handy), but it always gives an answer if the system is linear and diagonalisable.

$\endgroup$
  • 1
    $\begingroup$ Got the same result using generating functions. $\endgroup$ – Deep Joshi Sep 21 '17 at 6:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.