Did I correctly derive this recurrence equation formula

You can make it easier. Considering $$ x_{n+1}=a\,x_n+b $$ let $x_n=y_n+c$ to make $$y_{n+1}+c=a\, y_n+ac+b$$ that is to say $$y_{n+1}=a\, y_n+(ac+b-c)$$ Choose $c$ such that $ac+b-c=0$ and you are back to the classical geometric sequence. Solve it for $y_n$ and go back to $x_n$.


This is a linear recurrence with constant coefficients and it can also be solved similarly to a linear ODE.

The homogeneous equation is

$$x_{n+1}=ax_n$$ and obviously has the general solution

$$x_n=ca^n.$$

Now a particular solution of the non-homegeneous equation

$$x_{n+1}=ax_n+b$$ is given by a constant, let $d$, such that

$$d=ad+b.$$

We have

$$x_n=ca^n+\frac b{1-a}$$ and we plug the initial condition $x=x_0$,

$$x_0=c+\frac b{1-a}$$ and finally

$$x_n=a^nx_0+\frac{1-a^n}{1-a}b.$$


Other method:

The relation $x_{n+1}=ax_n$ hints the transformation $x_n=a^ny_n$, leading to the modified recurrence

$$y_{n+1}=y_n+ba^{-n},$$ which is solved by the summation of a geometric series

$$y_n=y_0+b\sum_{k=1}^na^{-k}=y_0+a^{-1}\frac{1-a^{-n}}{1-a^{-1}}.$$

Then

$$x_n=a^nx_0+\frac{a^n-1}{a-1}b.$$