1 Introduction

The nonhomogeneous linear difference equations are discrete dynamical systems, currently studied in the literature under the form,

$$\begin{aligned} y_{n+1}=a_0(n)y_{n-1}+a_1(n)y_{n-2}+\cdots + a_{r-1}(n)y_{n-r+1}+g(n), \hbox { for } n\ge r, \end{aligned}$$
(1)

where \(a_j: {\mathbb {N}}\rightarrow {\mathbb {R}}\) (\(0\le j\le r-1\)) and \(g: {\mathbb {N}}\rightarrow {\mathbb {R}}\) are given functions defined on \({\mathbb {N}}\). Recently, the homogeneous and nonhomogeneous linear difference equation (1), has attracted a lot of attention because of their wide applications in various fields of mathematics and applied sciences. That is, discrete time systems defined by Eq. (1), have several applications in economics, physics, circuit theory, and other areas. For example in finance, there is an application to the well-known Leontief model, or the Samuelson–Hicks model. For this former model, the nonhomogeneous linear difference equations of the second order plays a central role (see for instance [9, 13, 16], and references therein).

We recall that, when the coefficients \(a_j(n)\) (\(0\le j\le r-1\)) of the linear recurrences equation (1) are constants, namely, \(a_j(n)=a_j\), where \(a_j\) (\(0\le j\le r-1\)) is a constant, it is well known in the literature that the explicit solutions are expressed under a combinatorial form in terms of coefficients \(a_j\) (\(0\le j\le r-1\)) or under an analytic form, using the roots of the associated characteristic polynomial \(P(z)=z^r-a_0z^{r-1}-\cdots -a_{r-1}\) (see, for example, [11, 12], and references therein). However, when the coefficients \(a_j(n)\) (\(0\le j\le r-1\)) are variable, some methods have been elaborated in the literature for exhibiting formulas of the solutions of Eq. (1). That is, Kittapa gave solutions of the homogeneous linear difference equations of higher order with variable coefficients, in terms of a single matrix determinant (see [14]). In [15], the general solution for nonhomogeneous linear difference equations with variable coefficients, has been provided in terms of the determinant of a lower Hessenberg matrix. In [10], the explicit solution of the nonhomogeneous linear difference equation with variable coefficients is presented, in terms of matrix pencil theory. Malik established a closed form the solutions of (1), in terms of coefficients for the homogeneous linear difference equations with variable coefficients (see [17]). In [1], solutions of the homogeneous linear difference equations of the second order are studied in terms of the determinental approach and using the nested sum. Whereas, some explicit expressions of solutions of the homogeneous linear difference equations with periodic coefficients are established in [4].

In this paper, we present an alternative new method for solving the second order nonhomogeneous linear difference equations with periodic coefficients satisfying,

$$\begin{aligned} y_n=a_0(n)y_{n-1}+a_1(n)y_{n-2}+g_n, \end{aligned}$$
(2)

where \(\{g_n\}_{n\in {\mathbb {N}}}\) is a given real sequence and \(a_j: {\mathbb {N}}\rightarrow {\mathbb {R}}\;(j=0,1)\) are periodic functions of period \(p\in {\mathbb {N}}\), with \(p\ge 2\), namely \(a_0(n+p)=a_0(n)\) and \(a_1(n+p)=a_1(n)\), for every \(n\ge 0\). In our investigation, we provide explicit solutions of (2) by making use of some current results established in [8], on the periodic matrix difference equations related to Eq. (2). Moreover, the combinatorial and analytic formulas of linearly recurrence sequences of constants coefficients, will play a central role. More precisely, the matrix equation expression of Equation (2) and the periodicity condition, allow us to obtain an equivalent formulation of Eq. (2), as a family of nonhomogeneous linear difference equations of constant coefficients. This process leads to the resolution of Eq. (2), by applying the method of [12].

The study of this paper is structured as follows. Section 2 is devoted to the matrix formulation of the second-order difference Eq. (2), where the product of periodic companion matrices is considered. In addition, we give an explicit formula for the second member of the equivalent matrix equation. For this purpose, we develop algorithms for computing the finite product of companion matrices and give combinatorial expressions of powers of such class of matrices. In Sect. 3, we present the first approach, where we study the scalar nonhomogeneous matrix equation of order p with constant coefficients, emanated from the second-order Eq. (2). This allows us to provide the solutions of the homogeneous part and the particular solutions, to obtain the combinatorial and the analytic solutions of Eq. (2). Furthermore, an illustrative example is proposed as application of the results obtained. Section 4 concerns the second approach, where we manage to give other combinatorial and analytic expressions of the solutions of Eq. (2). Section 5 is devoted to the special case when the coefficients of Eq. (2) are periodic of period \( p=2 \). Finally, concluding remarks and discussion are considered.

2 Matrix formulation of the second-order difference equation (2)

2.1 General setting

Consider the second-order nonhomogeneous linear difference equation of periodic coefficients (2), namely,

$$\begin{aligned} y_n=a_0(n)y_{n-1}+a_1(n)y_{n-2}+g_n \;\;\;\;\;\hbox { for }\;\;\;n\ge 2, \end{aligned}$$

where \(y_0,\;y_1\) are the initial conditions, \( a_j: {\mathbb {N}}\rightarrow {\mathbb {R}}\;(j=0,1)\) are periodic functions of period \(p\in {\mathbb {N}}\) with \(p\ge 2\), namely \(a_j(n+p)=a_j(n)\) and \(\{g_n\}_{n\in {\mathbb {N}}}\) is a given real sequence. For reason of periodicity we set,

$$\begin{aligned} A(n)=\begin{pmatrix} a_0(n) &{} a_1(n) &{} 0 &{} \ldots &{} 0 \\ 1 &{} 0 &{} 0 &{} \ldots &{} 0\\ 0&{}1 &{} 0 &{} \ldots &{} 0\\ \vdots &{}\ddots &{}\ddots &{}\ddots &{}\vdots \\ 0 &{} \ldots &{} 0 &{} 1 &{} 0 \end{pmatrix}, U_{n+1}=\begin{pmatrix} g_n \\ 0 \\ \vdots \\ 0 \end{pmatrix}\; \; \hbox {and }\; \; Y_n=\begin{pmatrix} y_{n-1} \\ \vdots \\ y_{n-p} \end{pmatrix}. \end{aligned}$$

for every \( n\ge p \), where A(n) is a companion matrix of order \(p\times p\) and \(U_n\), \(Y_n\) are matrices of order \(p\times 1\). We observe that the periodicity condition of \(a_{0}(n)\), \(a_1(n)\) implies that \(A(n+p)=A(n)\), for every \(n\ge 0\). Meanwhile, we show that Eq. (2) is equivalent to the following nonhomogeneous matrix discrete equation,

$$\begin{aligned} Y_{n+1}=A(n)Y_n+U_{n+1}\;\;\;\;\hbox { for every }\;\;\;n\ge p. \end{aligned}$$
(3)

Expression (3) implies that, for every m such that \(n-m\ge p\), we have,

$$\begin{aligned} Y_{n+1}= & {} A(n)A(n-1)Y_{n-1}+A(n)U_n+U_{n+1}\\= & {} A(n)A(n-1)A(n-2)Y_{n-2}+A(n)A(n-1)U_{n-1}+A(n)U_n+U_{n+1}. \end{aligned}$$

More generally, an iterative prove leads to the following formula,

$$\begin{aligned} Y_{n+1}=\left[ \prod ^{*,m}_{0\le j\le m}A(n-j)\right] Y_{n-m}+ \sum _{s=0}^{m-1}\left( \prod ^{*,s}_{0\le j\le s}A(n-j)\right) U_{n-s}+U_{n+1}, \end{aligned}$$
(4)

where \(\prod \limits ^{*,k}_{0\le j\le k}A(n-j)=A(n)A(n-1)\ldots A(n-k)\), with \(\prod \limits ^{*,0}_{0\le j\le 0}A(n-j)=A(n)\). Especially, for \(m=n-p\) we get,

$$\begin{aligned} Y_{n+1}=\left[ \prod ^{*,n-p}_{0\le j\le n-p}A(n-j)\right] Y_{p}+ \sum _{s=0}^{n-p-1}\left( \prod ^{*,s}_{0\le j\le s}A(n-j)\right) U_{n-s}+U_{n+1}. \end{aligned}$$
(5)

When the matrix \(A(n)=A\) is a constant companion matrix, we show that Expression (5) represents a generalization of Expression (6) established in [12]. On the other hand, using the periodicity condition of the coefficients, a straightforward computation allows us to show that Expression (5) takes the following form:

$$\begin{aligned} Y_{kp}=B^{k-1}Y_{p}+\sum \limits _{i=0}^{k-2}B^{i}U_{(k-i)p}+\sum \limits _{i=0}^{k-2}B^{i} \sum \limits _{h=0}^{p-2}C(h)U_{(k-i)p-1-h}, \end{aligned}$$
(6)

for every \( k\ge 1 \), where

$$\begin{aligned} C(h)=A(p-1)...A(p-1-h) \hbox { and }B=C(p-1)=A(p-1)...A(0). \end{aligned}$$
(7)

By taking \(n=kp+m+1\), with \(0\le m\le p-2\), in Expression (4) and employing the periodicity conditions, i.e. \(A(kp+i)=A(i)\), we get the following formula:

$$\begin{aligned} Y_{kp+m+1}=\left[ \prod ^{*,m}_{0\le j\le m}A(m-j)\right] Y_{kp}+ \sum _{s=0}^{m-1} \left( \prod ^{*,s}_{0\le j\le s}A(m-j)\right) U_{kp+m-j}+U_{kp+m+1}. \end{aligned}$$
(8)

In summary, we have the following result.

Proposition 2.1

Consider the second-order nonhomogeneous linear difference equation of periodic coefficients (2), namely

$$\begin{aligned} y_n=a_0(n)y_{n-1}+a_1(n)y_{n-2}+g_n \;\;\;\;\;\hbox { for every }\;\;\;\;\;n\ge 2, \end{aligned}$$

where \(a_{0}(n)\) and \(a_1(n)\) are periodic functions of period \(p\ge 2\) and \(\{g_n\}_{n\in {\mathbb {N}}}\) is a given sequence. Then, for every \( k\ge 1 \), Eq. (2) is equivalent to the following system of p matrix equations (6) and (8), namely

$$\begin{aligned} \left\{ \begin{array}{lll} Y_{kp}=B^{k-1}Y_{p}+\sum \limits _{i=0}^{k-2}B^{i}U_{(k-i)p}+\sum \limits _{i=0}^{k-2}B^{i}\sum \limits _{h=0}^{p-2}C(h)U_{(k-i)p-1-h},\\ Y_{kp+m+1}=\left[ \prod \limits ^{*,m}_{0\le j\le m}A(m-j)\right] Y_{kp}+ \sum \limits _{s=0}^{m-1}\left( \prod \limits ^{*,s}_{0\le j\le s}A(m-j)\right) U_{kp+m-j}+U_{kp+m+1}, \end{array} \right. \end{aligned}$$

where \(0\le m\le p-2\) and the matrices B and C(h) are given by (7), namely,

$$\begin{aligned} C(h)=A(p-1)...A(p-1-h) \hbox { and }B=C(p-1)=A(p-1)...A(0). \end{aligned}$$

The matrix equation (3) shows that for solving Eq. (2), it is sufficient to compute only the \(Y_{kp}\), via the related matrix Expression (6). That is, it is not necessary to compute the \(Y_{kp+m+1}\) by solving Eq. (8). More precisely, it ensues from Proposition (2) our needed to compute C(h) and the powers \(B^n\). That is, for reasons of convenience and clarity, we can write the equation (6) under the following matrix equation,

$$\begin{aligned} Y_{kp}= & {} B^{k-1}Y_{p}+H_k, \end{aligned}$$
(9)

where

$$\begin{aligned} H_k=\sum \limits _{i=0}^{k-2}B^{i}U_{(k-i)p}+\sum \limits _{i=0}^{k-2}B^{i} \sum \limits _{h=0}^{p-2}C(h)U_{(k-i)p-1-h}. \end{aligned}$$
(10)

Equations (9)–(10) will play an important role in the process of resolution of Eq. (2), presented in the next Sections. That is, for solving Equation (2), we are led to compute the explicit formula of C(h) and the powers \(B^k\) of the constant matrix B.

2.2 Computation of the matrices C(h) and powers \(B^k\) (\(k\ge 1\))

Equation (6) can be written under the following matrix equation:

$$\begin{aligned} Z_{k}= & {} B^{k-1}Z_1+H_k,\;\;\;\ k\ge 1, \end{aligned}$$
(11)

where \(Z_k=Y_{kp}\) and \( H_k \) is given as in (10). Equation (11) shows that Eq. (2) is reduced to a nonhomogeneous matrix equation of constant matrix B, given as in (7). Thence, solving Equation (11) calls for the following requirements:

  • A process for the calculation of the matrix C(h) for \( 0\le h\le p-1 \),

  • A process for the calculation of the powers \(B^k\) of the matrix B.

Therefore, the main goal of this subsection is to implement a method for calculating the matrix \(C(h)\; (0\le h\le p-1)\) and the powers \(B^k\) of the matrix B.

First, put

$$\begin{aligned} C(h)= \begin{pmatrix} \alpha _{11}^{(h)} &{} \cdots &{} \alpha _{1p}^{(h)} \\ \vdots &{} \cdots &{} \vdots \\ \alpha _{p1}^{(h)} &{} \cdots &{} \alpha _{pp}^{(h)} \end{pmatrix}. \end{aligned}$$

It turns from Expression (7) that \(C(h)=C(h-1)A(p-1-h)\). Thus, a straightforward computation allows us to obtain,

$$\begin{aligned} C(h)=\begin{pmatrix} \alpha _{h}^{(h)} &{} \beta _{h}^{(h)} &{} 0 &{} \cdots \\ \alpha _{h-1}^{(h)} &{} \beta _{h-1}^{(h)} &{} 0 &{} \cdots \\ \alpha _{h-2}^{(h)} &{} \beta _{h-2}^{(h)} &{} 0 &{} \cdots \\ \vdots &{} \vdots &{} \vdots &{} \\ \alpha _{0}^{(h)} &{} \beta _{0}^{(h)} &{} 0 &{} \cdots \\ 1 &{} 0 &{} 0 &{} \cdots \\ 0 &{} 1 &{} 0 &{} \cdots \\ \vdots &{} \vdots &{} \ddots &{} \end{pmatrix}_{p\times p}, \hbox { for every }0\le h\le p-1, \end{aligned}$$

where \( \alpha _{j}^{(h)} \) and \( \beta _{j}^{(h)}\;(0\le j\le h) \) are computed by the following algorithm,

$$\begin{aligned} \left\{ \begin{aligned}&\alpha _{j}^{(h)}=\alpha _{j-1}^{(h-1)}a_0(p-1-h) +\alpha _{j-2}^{(h-2)}a_1(p-h), \\&\beta _{j}^{(h)}=\alpha _{j-1}^{(h-1)}a_1(p-1-h), \end{aligned} \right. \end{aligned}$$
(12)

with the initial conditions \( \alpha _{-1}^{(h-2)}=1\) and \(\alpha _{-2}^{(h-2)}=0 \), for every \( h\ge 0 \).

Second, let now compute the entries of the powers \(B^k\) of the matrix B, given as in (7). Since \(B=C(p-1)\) we have,

$$\begin{aligned} B=\begin{pmatrix} \alpha _{p-1}^{(p-1)} &{} \beta _{p-1}^{(p-1)} &{} 0 &{} \cdots \\ \alpha _{p-2}^{(p-1)} &{} \beta _{p-2}^{(p-1)} &{} 0 &{} \cdots \\ \vdots &{} \vdots &{} \vdots &{} \\ \alpha _{0}^{(p-1)} &{} \beta _{0}^{(p-1)} &{} 0 &{} \cdots \end{pmatrix},\;\;\;\hbox { with }\;\; p\ge 2, \end{aligned}$$

where the \(\alpha _{j}^{(h)}\) and the \(\beta _{j}^{(h)}\) are as in (12). For \( k\ge 1 \), we put

$$\begin{aligned} B^k=\begin{pmatrix} \theta _{1}^{(k)} &{} \gamma _{1}^{(k)} &{} 0 &{} \cdots \\ \theta _{2}^{(k)} &{} \gamma _{2}^{(k)} &{} 0 &{} \cdots \\ \vdots &{} \vdots &{} \vdots \\ \theta _{p}^{(k)} &{} \gamma _{p}^{(k)} &{} 0 &{} \cdots \end{pmatrix}, \end{aligned}$$
(13)

with

$$\begin{aligned} \left\{ \begin{aligned}&\theta _{j}^{(1)}=\alpha _{p-j}^{(p-1)},\\&\gamma _{j}^{(1)}=\beta _{p-j}^{(p-1)}, \end{aligned} \right. \;\;\; \hbox {for} \;\; j=1,2,...,p. \end{aligned}$$
(14)

And as \( B^k=B^{k-1}.B \), in other terms,

$$\begin{aligned} \begin{pmatrix} \theta _{1}^{(k)} &{} \gamma _{1}^{(k)} &{} 0 &{} \cdots \\ \theta _{2}^{(k)} &{} \gamma _{2}^{(k)} &{} 0 &{} \cdots \\ \vdots &{} \vdots &{} \vdots \\ \theta _{p}^{(k)} &{} \gamma _{p}^{(k)} &{} 0 &{} \cdots \end{pmatrix} =\begin{pmatrix} \theta _{1}^{(k-1)} &{} \gamma _{1}^{(k-1)} &{} 0 &{} \cdots \\ \theta _{2}^{(k-1)} &{} \gamma _{2}^{(k-1)} &{} 0 &{} \cdots \\ \vdots &{} \vdots &{} \vdots \\ \theta _{p}^{(k-1)} &{} \gamma _{p}^{(k-1)} &{} 0 &{} \cdots \end{pmatrix}. \begin{pmatrix} \theta _{1}^{(1)} &{} \gamma _{1}^{(1)} &{} 0 &{} \cdots \\ \ theta_{2}^{(1)} &{} \gamma _{2}^{(1)} &{} 0 &{} \cdots \\ \vdots &{} \vdots &{} \vdots \\ \theta _{p}^{(1)} &{} \gamma _{p}^{(1)} &{} 0 &{} \cdots \end{pmatrix}, \end{aligned}$$

we conclude that, for every \( j=1,2,...,p \), we have the following recursive relations,

$$\begin{aligned} \left\{ \begin{aligned}&\theta _{j}^{(k)}=\theta _{j}^{(k-1)}\theta _{1}^{(1)}+\gamma _{j}^{(k-1)}\theta _{2}^{(1)}, \\&\gamma _{j}^{(k)}=\theta _{j}^{(k-1)}\gamma _{1}^{(1)}+\gamma _{j}^{(k-1)}\gamma _{2}^{(1)}. \end{aligned} \right. \end{aligned}$$

Thereafter, we get the following homogeneous matrix equation,

$$\begin{aligned} \begin{pmatrix} \theta _{j}^{(k)} \\ \gamma _{j}^{(k)} \end{pmatrix}= \begin{pmatrix} \theta _{1}^{(1)}&{} \theta _{2}^{(1)} \\ \gamma _{1}^{(1)} &{} \gamma _{2}^{(1)} \end{pmatrix}.\begin{pmatrix} \theta _{j}^{(k-1)} \\ \gamma _{j}^{(k-1)} \end{pmatrix}=\begin{pmatrix} \theta _{1}^{(1)}&{} \theta _{2}^{(1)} \\ \gamma _{1}^{(1)} &{} \gamma _{2}^{(1)} \end{pmatrix}^2.\begin{pmatrix} \theta _{j}^{(k-2)} \\ \gamma _{j}^{(k-2)} \end{pmatrix}. \end{aligned}$$

Put \( Q=\begin{pmatrix} \theta _{1}^{(1)}&{} \theta _{2}^{(1)} \\ \gamma _{1}^{(1)} &{} \gamma _{2}^{(1)} \end{pmatrix} \), then by induction, we acquire,

$$\begin{aligned} \begin{pmatrix} \theta _{j}^{(k)} \\ \gamma _{j}^{(k)} \end{pmatrix}=Q^{k-1}\begin{pmatrix} \theta _{j}^{(1)} \\ \gamma _{j}^{(1)} \end{pmatrix}, \end{aligned}$$

for every \( j=1,2,...,p \). Let us consider the characteristic polynomial of Q, namely, \( P_Q(z)=det(Q-zI_2)=(\theta _{1}^{(1)}-z)(\gamma _{2}^{(1)}-z)-\theta _{2}^{(1)}\gamma _{1}^{(1)}=z^2-c_1z-c_2 \), where

$$\begin{aligned} \left\{ \begin{aligned}&c_1=\theta _{1}^{(1)}+\gamma _{2}^{(1)}=\alpha _{p-1}^{(p-1)}+\beta _{p-2}^{(p-1)}, \\&c_2= \theta _{2}^{(1)}\gamma _{1}^{(1)}-\theta _{1}^{(1)}\gamma _{2}^{(1)}= \alpha _{p-2}^{(p-1)} \beta _{p-1}^{(p-1)}-\alpha _{p-1}^{(p-1)}\beta _{p-2}^{(p-1)}. \end{aligned} \right. \end{aligned}$$
(15)

Using the combinatorial formula, on the powers of matrix established in [6], we obtain,

$$\begin{aligned} Q^n=\rho (n,2)\left[ c_1Q+c_2I_2\right] +\rho (n-1,2)c_2Q=\rho (n+1,2)Q+c_2\rho (n,2)I_2, \end{aligned}$$

for \( n\ge 2 \), with \( \rho (1,2)=0,\,\rho (2,2)=1 \), and

$$\begin{aligned} \rho (n,2)=\sum \limits _{h_1+2h_2=n-2}\left( {\begin{array}{c}h_1+h_2\\ h_1,\; h_2\end{array}}\right) c_1^{h_1}c_2^{h_2}=\sum \limits _{h=0}^{[\frac{n-2}{2}]} \left( {\begin{array}{c}n-h-2\\ h\end{array}}\right) c_1^{n-2h-2}c_2^h, \end{aligned}$$
(16)

for all \( n\ge 2\). As a matter of fact, we have the following combinatorial expression for the entries of the matrix \(Q^n\),

$$\begin{aligned} Q^n=\begin{pmatrix} \theta _{1}^{(1)}\rho (n+1,2)+c_2\rho (n,2) &{} \theta _{2}^{(1)}\rho (n+1,2) \\ \gamma _{1}^{(1)}\rho (n+1,2) &{} \gamma _{2}^{(1)}\rho (n+1,2)+c_2\rho (n,2) \end{pmatrix}. \end{aligned}$$

Therefore, we get the following lemma,

Lemma 2.2

With the same notation as above, the combinatorial formula of the powers of the matrix B, is given by,

$$\begin{aligned} B^k=\begin{pmatrix} \theta _{1}^{(k)} &{} \gamma _{1}^{(k)} &{} 0 &{} \cdots \\ \theta _{2}^{(k)} &{} \gamma _{2}^{(k)} &{} 0 &{} \cdots \\ \vdots &{} \vdots &{} \vdots \\ \theta _{p}^{(k)} &{} \gamma _{p}^{(k)} &{} 0 &{} \cdots \end{pmatrix}, \end{aligned}$$

for every \(k\ge 2\), where

$$\begin{aligned} {\left\{ \begin{array}{ll} \theta _{j}^{(k)}= \left( \theta _{1}^{(1)}\rho (k,2)+c_2\rho (k-1,2)\right) \theta _{j}^{(1)} + \rho (k,2)\theta _{2}^{(1)} \gamma _{j}^{(1)}, \\ \gamma _{j}^{(k)} =\rho (k,2)\gamma _{1}^{(1)} \theta _{j}^{(1)}+\left( \gamma _{2}^{(1)}\rho (k,2)+c_2\rho (k-1,2)\right) \gamma _{j}^{(1)}, \end{array}\right. } \end{aligned}$$

such that \(\rho (n,2)=\sum \limits _{h=0}^{[\frac{n-2}{2}]} \left( {\begin{array}{c}n-h-2\\ h\end{array}}\right) c_1^{n-2\,h-2}c_2^h\), for \( n>2 \), with \( \rho (1,2)=0\), \(\rho (2,2)=1 \), and \(\theta _{j}^{(1)} \), \(\gamma _{j}^{(1)} \) are given by (12)–(14).

It follows from the above Lemma 2.2 that the entries of the powers \(B^k\) are expressed in terms of the combinatorial expression \(\rho (n,2)\), namely, Expression (16). Furthermore, we point out that the sequence \(\{v_n\}_{n\ge 0}\) defined by \(v_n=\rho (n+1,2)\), for \(n\ge 0\), satisfies the linear recursive relation of Fibonacci type \(v_{n+2}=c_0v_{n+1}+c_1v_n\), for \(n\ge 0\), with initial data \(v_0=0 \) and \(v_1=1 \) ( For more details see [6]).

Moreover, let \(\lambda _1\) and \(\lambda _2\) be the roots of the characteristic polynomial \(P(z)=z^{2}-c_1z-c_2\), of the sequence \(\left\{ v_n=\rho (n+1,2)\right\} _{n\ge 0}\). Then, we have \( P(z)=(z-\lambda _1)(z-\lambda _2) \). First, suppose that \(\lambda _1\not = \lambda _2\), it ensues from [5, Lemma 2.1, Expression (6)] that,

$$\begin{aligned} \rho (n,2)=\sum \limits _{i=1}^{2}\dfrac{\lambda _i^{n-1}}{P'(\lambda _i)}=\dfrac{\lambda _1^{n-1}}{P'(\lambda _1)}+\dfrac{\lambda _2^{n-1}}{P'(\lambda _2)},\;\;\hbox { for every }\;\; n\ge 1. \end{aligned}$$
(17)

Thence, we get the analytic expression of the matrix powers \(Q^n\) as follows:

$$\begin{aligned} Q^n=\begin{pmatrix} \sum \limits _{i=1}^{2}\dfrac{\theta _{1}^{(1)}\lambda _i+c_2}{P'(\lambda _i)}\lambda _i^{n-1} &{} \theta _{2}^{(1)}\sum \limits _{i=1}^{2}\dfrac{\lambda _i^{n}}{P'(\lambda _i)} \\ \gamma _{1}^{(1)}\sum \limits _{i=1}^{2}\dfrac{\lambda _i^{n}}{P'(\lambda _i)} &{} \sum \limits _{i=1}^{2}\dfrac{\gamma _{2}^{(1)}\lambda _i+c_2}{P'(\lambda _i)}\lambda _i^{n-1} \end{pmatrix}, \hbox { for every } n\ge 2, \end{aligned}$$

and using the fact that \( \begin{pmatrix} \theta _{j}^{(k)} \\ \gamma _{j}^{(k)} \end{pmatrix}=Q^{k-1}\begin{pmatrix} \theta _{j}^{(1)} \\ \gamma _{j}^{(1)} \end{pmatrix} \), for every \( k\ge 2 \), we can formulate the following lemma.

Lemma 2.3

With the same notation as above, when \(\lambda _1 \ne \lambda _2\) the analytic formula of the powers of the matrix B is given by,

$$\begin{aligned} B^k=\begin{pmatrix} \theta _{1}^{(k)} &{} \gamma _{1}^{(k)} &{} 0 &{} \cdots \\ \theta _{2}^{(k)} &{} \gamma _{2}^{(k)} &{} 0 &{} \cdots \\ \vdots &{} \vdots &{} \vdots \\ \theta _{p}^{(k)} &{} \gamma _{p}^{(k)} &{} 0 &{} \cdots \end{pmatrix},\;\;\; \hbox {for every}\; k\ge 2, \end{aligned}$$

where

$$\begin{aligned} {\left\{ \begin{array}{ll} \theta _{j}^{(k)}= \left( \sum \limits _{i=1}^{2}\dfrac{\theta _{1}^{(1)}\lambda _i+c_2}{P'(\lambda _i)}\lambda _i^{k-2}\right) \theta _{j}^{(1)} + \left( \sum \limits _{i=1}^{2}\dfrac{\theta _{2}^{(1)}\lambda _i^{k-1}}{P'(\lambda _i)}\right) \gamma _{j}^{(1)}, \\ \gamma _{j}^{(k)} =\left( \sum \limits _{i=1}^{2}\dfrac{\gamma _{1}^{(1)}\lambda _i^{k-1}}{P'(\lambda _i)}\right) \theta _{j}^{(1)}+\left( \sum \limits _{i=1}^{2}\dfrac{\gamma _{2}^{(1)}\lambda _i+c_2}{P'(\lambda _i)}\lambda _i^{k-2}\right) \gamma _{j}^{(1)}, \end{array}\right. } \end{aligned}$$

and \(\theta _{j}^{(1)} \), \(\gamma _{j}^{(1)} \) are given as in (12)—(14).

Second, suppose that \(\lambda _1= \lambda _2=\lambda \). Then, the analytic expression of \(\{ \rho (n,2)\}_{n\ge 1}\) is given by \(\displaystyle \rho (n,2)=(\alpha _1+\alpha _2n)\lambda ^n\). Since \(\rho (1,2)=0\) and \(\rho (2,2)=1\), we infer that \((\alpha _1+\alpha _2)\lambda =0\) and \((\alpha _1+2\alpha _2)\lambda ^2=1\). Hence, we conclude that \(\alpha _1=-\alpha _2\) and \(\alpha _1+2\alpha _2=\frac{1}{\lambda ^2}\), thereby, \(\alpha _1=-\frac{1}{\lambda ^2}\) and \(\alpha _2=\frac{1}{\lambda ^2}\). Accordingly we obtain,

$$\begin{aligned} \rho (n,2)=(n-1)\lambda ^{n-2}, \hbox { for every } n\ge 1. \end{aligned}$$
(18)

Summarizing, we get the following lemma.

Lemma 2.4

With the same notation as above, when \(\lambda _1= \lambda _2=\lambda \) the analytic formula of the powers \(B^k\) of the matrix B is given by,

$$\begin{aligned} B^k=\begin{pmatrix} \theta _{1}^{(k)} &{} \gamma _{1}^{(k)} &{} 0 &{} \cdots \\ \theta _{2}^{(k)} &{} \gamma _{2}^{(k)} &{} 0 &{} \cdots \\ \vdots &{} \vdots &{} \vdots \\ \theta _{p}^{(k)} &{} \gamma _{p}^{(k)} &{} 0 &{} \cdots \end{pmatrix},\; \hbox {for every}\; k\ge 2, \end{aligned}$$

where

$$\begin{aligned} {\left\{ \begin{array}{ll} \theta _{j}^{(k)}= \left( (k-1)(\theta _{1}^{(1)}\lambda +c_2)-c_2\right) \lambda ^{k-3}\theta _{j}^{(1)} + \theta _2^{(1)}(k-1)\lambda ^{k-2} \gamma _{j}^{(1)}, \\ \gamma _{j}^{(k)} =\gamma _{1}^{(1)}(k-1)\lambda ^{k-2} \theta _{j}^{(1)}+\left( (k-1)(\gamma _{2}^{(1)}\lambda +c_2)-c_2\right) \lambda ^{k-3} \gamma _{j}^{(1)}, \end{array}\right. } \end{aligned}$$

and \(\theta _{j}^{(1)} \), \(\gamma _{j}^{(1)} \) are given by (12)—(14).

2.3 Matrix formulation of Eq. (2)

Consider the characteristic polynomial of the matrix B, given as follows:

$$\begin{aligned} P_B(z)=det(B-zI_p)=z^{p-2}(z^2-c_1z-c_2), \end{aligned}$$

with

$$\begin{aligned} c_1=\theta _{1}^{(1)}+\gamma _{2}^{(1)} \; \hbox { and }\; c_2=\theta _{2}^{(1)}\gamma _{1}^{(1)}-\theta _{1}^{(1)}\gamma _{2}^{(1)}, \end{aligned}$$
(19)

where \(\theta _{j}^{(1)} \) and \(\gamma _{j}^{(1)} ( j=1, 2 \)) are given by (12)—(14). We point out that \(c_1 \) and \(c_2 \) are nothing else but only the coefficients of \( P_Q(x) \), the characteristic polynomial of the matrix Q, given by (15).

Since \( P_B(B)=\Theta \) (the matrix null), the Cayley–Hamilton Theorem implies that \(B^{p}=c_1B^{p-1}+c_2B^{p-2}\). Therefore, we conclude that

$$\begin{aligned} B^{p}B^{k-1}Y_p=c_1B^{p-1}B^{k-1}Y_p+c_2B^{p-2}B^{k-1}Y_p, \;\hbox { for every} \; k\ge 1, \end{aligned}$$

or equivalently,

$$\begin{aligned} B^{p+k-1}Y_p=c_1B^{p+k-2}Y_p+c_2B^{p+k-3}Y_p, \;\hbox { for every } \; k\ge 1, \; \hbox { with } \; Y_p=\begin{pmatrix} y_{p-1} \\ \vdots \\ y_{0} \end{pmatrix}. \end{aligned}$$

Equations (9)–(10) yield,

$$\begin{aligned} Y_{(p+k)p}-H_{p+k} = c_1Y_{(p-1+k)p}-c_1H_{p-1+k}+c_2Y_{(p-2+k)p}-c_2H_{p-2+k},\;\hbox {for every} \; k\ge 1, \end{aligned}$$

where \( H_{s} \) is given as in (10), namely,

$$\begin{aligned} H_{s}=\sum \limits _{i=0}^{s-2}B^{i}U_{(s-i)p}+\sum \limits _{i=0}^{s-2}B^{i}\sum \limits _{h=0}^{p-2}C(h)U_{(s-i)p-1-h}, \end{aligned}$$

for \(s=p+k,\;p+k-1,\;p+k-2\). Consequently, the sequence \(\{ Y_{(p+k)p}\}_{k\ge 0}\), satisfies the following nonhomogeneous linear recursive relation,

$$\begin{aligned} Y_{(p+k)p}=c_1Y_{(p-1+k)p}+c_2Y_{(p-2+k)p}+H^{*}_k, \end{aligned}$$
(20)

with \( H^{*}_k=H_{p+k}-c_1H_{p-1+k}-c_2H_{p-2+k} \). Equation (20) represents another equivalent expression of Eq. (3). And by a direct computation we obtain,

$$\begin{aligned} H^{*}_k=\left( B^{2}-c_1B-c_2I_p\right) \left( \sum \limits _{i=0}^{p+k-4}B^{i}D_{k-2-i}\right) +\left( B-c_1I_p\right) D_{k-1}+D_k, \end{aligned}$$
(21)

where \(D_k=U_{(p+k)p}+\sum \limits _{h=0}^{p-2}C(h)U_{(p+k)p-1-h}\). Equations (20)–(21) will play a central role in the resolution of Eq. (2). To this aim, let us compute the explicit formula for each entry of the matrix column \(H^{*}_k\). We first show that

$$\begin{aligned} D_k=\begin{pmatrix} \sum \limits _{h=-1}^{p-2} \alpha _{h}^{(h)}g_{(p+k)p-2-h}\\ \sum \limits _{h=0}^{p-2} \alpha _{h-1}^{(h)}g_{(p+k)p-2-h}\\ \sum \limits _{h=1}^{p-2} \alpha _{h-2}^{(h)}g_{(p+k)p-2-h}\\ \vdots \\ \sum \limits _{h=p-3}^{p-2}\alpha _{h-p+2}^{(h)}g_{(p+k)p-2-h}\\ g_{(p+k)p-p} \end{pmatrix}, \end{aligned}$$
(22)

where \( \alpha _{j}^{(h)} \) are given by (12). Thence, for every \( i=0,1,...,p+k-4\), we get \( B^iD_{k-2-i}=\begin{pmatrix} x_1^{(i)}\\ x_2^{(i)}\\ \vdots \\ x_p^{(i)} \end{pmatrix},\) with

$$\begin{aligned} \left\{ \begin{aligned}&x_j^{(i)} = \sum \limits _{h=-1}^{p-2} \left[ \theta _{j}^{(i)}\alpha _{h}^{(h)}+\gamma _{j}^{(i)}\alpha _{h-1}^{(h)}\right] g_{(p+k-2-i)p-2-h} \;\;\;\; (i\ne 0), \\&x_j^{(0)} = \sum \limits _{h=j-2}^{p-2}\alpha _{h-j+1}^{(h)}\;g_{(p+k-2)p-2-h}. \end{aligned} \right. \end{aligned}$$
(23)

Moreover, a straightforward computation allows us to conclude that

$$\begin{aligned} B^{2}-c_1B-c_2I_p=\begin{pmatrix} \theta _{1}^{(2)}-c_1\theta _{1}^{(1)}-c_2 &{} \gamma _{1}^{(2)}-c_1\gamma _{1}^{(1)} &{} 0 &{} \cdots &{} 0 \\ \theta _{2}^{(2)}-c_1\theta _{2}^{(1)} &{} \gamma _{2}^{(2)}-c_1\gamma _{2}^{(1)}-c_2 &{} 0 &{} \cdots &{} 0 \\ \theta _{3}^{(2)}-c_1\theta _{3}^{(1)} &{} \gamma _{3}^{(2)}-c_1\gamma _{3}^{(1)} &{} -c_2 &{} \cdots &{} 0 \\ \vdots &{} \vdots &{} \vdots &{} &{} \vdots \\ \theta _{p}^{(2)}-c_1\theta _{p}^{(1)} &{} \gamma _{p}^{(2)}-c_1\gamma _{p}^{(1)} &{} 0 &{} \cdots &{} -c_2 \\ \end{pmatrix}, \end{aligned}$$

where \(c_1\) and \(c_2\) are as in (15). We can show that,

$$\begin{aligned} \left( B^{2}-c_1B-c_2I_p\right) \left( \sum \limits _{i=0}^{p+k-4}B^{i}D_{k-2-i}\right) =\begin{pmatrix} z_1^{(k)}\\ z_2^{(k)}\\ \vdots \\ z_p^{(k)}, \end{pmatrix} \end{aligned}$$

with

$$\begin{aligned} z_j^{(k)}=\left( \theta _{j}^{(2)}-c_1\theta _{j}^{(1)} \right) \sum \limits _{i=0}^{p+k-4}x_1^{(i)} +\left( \gamma _{j}^{(2)}-c_1\gamma _{j}^{(1)} \right) \sum \limits _{i=0}^{p+k-4}x_2^{(i)} -c_2\sum \limits _{i=0}^{p+k-4}x_j^{(i)}. \end{aligned}$$
(24)

Furthermore, we have, \( (B-c_1I_p)D_{k-1}=\begin{pmatrix} v_1^{(k)}\\ v_2^{(k)}\\ \vdots \\ v_p^{(k)} \end{pmatrix},\) such that

$$\begin{aligned} \left. \begin{aligned}&v_j^{(k)}= \theta _{j}^{(1)}\sum \limits _{h=-1}^{p-2} \alpha _{h}^{(h)}\;g_{(p+k-1)p-2-h}+\gamma _{j}^{(1)}\sum \limits _{h=0}^{p-2} \alpha _{h-1}^{(h)}\;g_{(p+k-1)p-2-h} \\&\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; -c_1\sum \limits _{h=j-2}^{p-2} \alpha _{h-j+1}^{(h)}\;g_{(p+k-1)p-2-h}. \end{aligned} \right. \end{aligned}$$
(25)

By combining Expressions (23), (24) and (25), we obtain the following explicit expression of \(H^{*}_k\).

Lemma 2.5

With the same notation as above, the explicit formula of \( H^{*}_k=\begin{pmatrix} \varphi ^{(k)}_1\\ \varphi ^{(k)}_2 \\ \vdots \\ \varphi ^{(k)}_p \end{pmatrix} \) is given by

$$\begin{aligned} \varphi ^{(k)}_j = z_j^{(k)}+v_j^{(k)}+ \sum \limits _{h=j-2}^{p-2} \alpha _{h-j+1}^{(h)}g_{(p+k)p-2-h} \;\;\;\hbox { where }\;\;\;j=1,2,...,p, \end{aligned}$$
(26)

where \( \alpha _{j}^{(h)} \), \(z_j^{(k)}\) and \(v_j^{(k)}\) are given by (12), (24), (25), respectively.

In the next sections, Lemmas 2.3, 2.4 and 2.5 will be extensively used for establishing various explicit expressions of the solutions of Eq. (2), namely, the analytic and the combinatorial formulas of the solutions of Eq. (2).

3 Solutions of Eq. (2)—first approach

The main steps of our process for solving Eq. (2), consist of considering the equivalent non-homogeneous matrix equation (3). Thanks to the condition of periodicity of the coefficients \(a_1(n)\), \(a_2(n) \), the matrix form (3) permits us to establish that it is equivalent to a nonhomogeneous matrix equation with constant coefficients, namely, Eq. (20). More precisely, in light of Eq. (20), we observe that the matrix sequence \(\{ Y_{(p+k)p}\}_{k\ge 1}\), satisfies the following recursive relation:

$$\begin{aligned} Y_{(p+k)p}=c_1Y_{(p-1+k)p}+c_2Y_{(p-2+k)p}+H^{*}_k, \end{aligned}$$

where \(c_1\), \(c_2\) are the coefficients given by (19) and \( H^{*}_k=H_{p+k}-c_1H_{p-1+k}-c_2H_{p-2+k} \) is the matrix column (21).

3.1 Solutions of the homogeneous part of Eq. (20).

Let us consider the homogeneous matrix recurrence relation of order 2, related to Eq. (20), given by,

$$\begin{aligned} Y_{(p+k)p}=c_1Y_{(p-1+k)p}+c_2Y_{(p-2+k)p}. \end{aligned}$$

Hence, by considering the entries of each vector of the former equation, we conclude that Eq. (2) is equivalent, to the following scalar p equations:

$$\begin{aligned} y_{kp+p(p-1)+j}=c_1y_{kp+p(p-2)+j}+c_2y_{kp+p(p-3)+j},\;\;\;\;\hbox { where }\;\;\;\;\;j=0,\cdots ,p-1, \end{aligned}$$

for \( k\ge 1\). By setting \( n=k+p-1 \), we get,

$$\begin{aligned} y_{np+j}=c_1y_{(n-1)p+j}+c_2y_{(n-2)p+j},\;\;\;\;\hbox { where } \;\;\;\;\;j=0,\cdots ,p-1, \end{aligned}$$
(27)

for every \(n\ge p\). For reason of clarity, we denote by \( y_{np+j}^{<h>} \) the solutions of the former Eq. (27). For every \(j=0,1,\cdots ,p-1\), we consider the sequence \(\{w_{m}^{(j)}\}_{m\ge 0} \) defined by \( w_m^{(j)}=y_{mp+p(p-2)+j}^{<h>} \). Therefore, the sequence \(\{w_{m}^{(j)}\}_{m\ge 0} \) is a linear recursive sequence of order 2, of Fibonacci type, fulfilled the following the linear recurrence relation:

$$\begin{aligned} w_{m}^{(j)}=c_1w_{m-1}^{(j)}+c_2w_{m-2}^{(j)},\;\;\;\;\hbox { for }\;\;m\ge 2, \end{aligned}$$
(28)

with initial conditions \( w_{0}^{(j)}=y_{(p-2)p+j} \), \( w_{1}^{(j)}=y_{(p-1)p+j} \), whose related characteristic polynomial is \( P(z)=z^{2}-c_1z-c_2\). Thus, the combinatorial formula of \(\{w_{m}^{(j)}\}_{m\ge 0} \) is given by,

$$\begin{aligned} w_{m}^{(j)}=\rho (m,2)[c_2w_0^{(j)}+c_1w_1^{(j)}]+\rho (m-1,2)c_2w_1^{(j)}, \;\;\;\;\hbox { for } \;\;m\ge 2, \end{aligned}$$
(29)

where \( \rho (m,2) \) is given by (16), namely

$$\begin{aligned} \rho (m,2)=\sum \limits _{h_1+2h_2=m-2}\left( {\begin{array}{c}h_1+h_2\\ h_1,\; h_2\end{array}}\right) c_1^{h_1}c_2^{h_2}=\sum \limits _{h=0}^{[\frac{m-2}{2}]} \left( {\begin{array}{c}m-h-2\\ h\end{array}}\right) c_1^{m-2h-2}c_2^h, \end{aligned}$$

with \( \rho (1,2)=0\) and \(\rho (2,2)=1 \).

In addition, employing the analytic formulas of \( \rho (m,2) \) given by (17) and (18), we can obtain the analytic expression of the sequence \(\{w_{m}^{(j)}\}_{m\ge 0} \). As a matter of fact, let \(\lambda _1\), \(\lambda _2\) be the roots of the characteristic polynomial \(P(z)=z^{2}-c_1z-c_2\). For \( \lambda _1\ne \lambda _2 \), Expression (17) shows that \(\displaystyle \rho (m,2)=\sum \limits _{i=1}^{2}\dfrac{\lambda _i^{m-1}}{P'(\lambda _i)}=\dfrac{\lambda _1^{m-1}}{P'(\lambda _1)}+\dfrac{\lambda _2^{m-1}}{P'(\lambda _2)}\), for every \(m\ge 2\). So, in this case we get,

$$\begin{aligned} w_{m}^{(j)}=\sum \limits _{i=1}^{2}\dfrac{\lambda _i(c_2w_{0}^{(j)}+c_1w_{1}^{(j)})+c_2w_{1}^{(j)}}{P'(\lambda _i)}\lambda _i^{m-2}. \end{aligned}$$

Second, for \(\lambda _1= \lambda _2=\lambda \), the analytic expression (18) of \(\{ \rho (m,2)\}_{m\ge 0}\), given by \(\displaystyle \rho (m,2)=(m-1)\lambda ^{m-2}\), for every \(m\ge 2\), allows us to obtain,

$$\begin{aligned} w_{m}^{(j)}=\left[ (m-1)c_2\lambda w_{0}^{(j)}+((m-1)c_1\lambda +(m-2)c_2)w_{1}^{(j)} \right] \lambda ^{m-3}. \end{aligned}$$

Since, for \(j=0,1,\cdots ,p-1\), we have \( w_m^{(j)}=y_{mp+p(p-2)+j}^{<h>} \), for every \(m\ge 2\), we get the following result.

Proposition 3.1

With the same notation as above, for every \( j=0,...,p-1 \), the combinatorial solution of the homogeneous Eq. (27), \( y_{np+j}=c_1y_{(n-1)p+j}+c_2y_{(n-2)p+j} \), is given by,

$$\begin{aligned} y_{np+j}^{<h>}=c_2\rho (n-p+2,2)y_{(p-2)p+j}+\rho (n-p+3,2)y_{(p-1)p+j}. \end{aligned}$$

Furthermore, if \(\lambda _1\) and \(\lambda _2\) are the roots of the characteristic polynomial \(P(z)=z^{2}-c_1z-c_2\), the analytic solution of the homogeneous Eq. (27), is given as follows.

1) If \(\lambda _1\not = \lambda _2\) then, for every \( j=0,...,p-1 \), we have,

$$\begin{aligned} y_{np+j}^{<h>}=\sum \limits _{i=1}^{2}\dfrac{c_2\lambda _iy_{(p-2)p+j}+\lambda _i^2y_{(p-1)p+j}}{P'(\lambda _i)}\lambda _i^{n-p}, \hbox { for } n\ge p. \end{aligned}$$

2) If \(\lambda _1 = \lambda _2=\lambda \) then, for every \( j=0,...,p-1 \), we have,

$$\begin{aligned} y_{np+j}^{<h>}=\left[ (n-p+1)c_2\lambda y_{(p-2)p+j}+((n-p)\lambda ^2+c_1\lambda )y_{(p-1)p+j} \right] \lambda ^{n-p-1}, \hbox { for } n\ge p. \end{aligned}$$

3.2 Particular solutions of Eq. (20).

Consider the nonhomogeneous equation (20),

$$\begin{aligned} Y_{(p+k)p}=c_1Y_{(p-1+k)p}+c_2Y_{(p-2+k)p}+H^{*}_k, \; k\ge 1, \end{aligned}$$

with initial conditions \( Y_{p^2}\) and \(Y_{(p-1)p} \). Then, Eq. (20) implies that the entries of the vector \(Y_{kp}\) satisfy the nonhomogeneous scalar equations, of constant coefficients, given by,

$$\begin{aligned} y_{np+j}=c_1y_{(n-1)p+j}+c_2y_{(n-2)p+j}+\varphi ^{(k)}_{p-j}, \; \; \hbox { for } 0\le j\le p-1. \end{aligned}$$
(30)

The nonhomogeneous scalar equation of type (30) have been studied in [12]. More precisely, we exploit the formula given in [12, Theorem 3.1], we can obtain the explicit form, for a particular solution of Eq. (30), which we present in the following proposition.

Proposition 3.2

With the same notation as above, the particular solutions of Eq. (30) can be expressed under the combinatorial form as follows:

$$\begin{aligned} y_{np+j}^{<p>}=\sum \limits _{i=2}^{n-p+2}\rho (n-p-i+4,2)\varphi ^{(i-1)}_{p-j}. \end{aligned}$$
(31)

Furthermore, if \( \lambda _1\) and \(\lambda _2 \) are the roots of the polynomial \( P(z)=z^{2}-c_1z-c_2\). Then, employing (17)–(18), the particular solutions of Eq. (30) can be expressed under an analytic form as follows:

1) If \(\lambda _1\not = \lambda _2\) then, for every \( j=0,...,p-1 \), we have,

$$\begin{aligned} y_{np+j}^{<p>}=\sum \limits _{i=2}^{n-p+2}\left[ \dfrac{\lambda _1^{n-p-i+3}}{P'(\lambda _1)}+\dfrac{\lambda _2^{n-p-i+3}}{P'(\lambda _2)} \right] \varphi ^{(i-1)}_{p-j}, \hbox { for } n\ge p. \end{aligned}$$
(32)

2) If \(\lambda _1 = \lambda _2=\lambda \) then, for every \( j=0,...,p-1 \), we have,

$$\begin{aligned} y_{np+j}^{<p>} = \sum \limits _{i=2}^{n-p+2}(n-p-i+3)\lambda ^{n-p-i+2}\varphi ^{(i-1)}_{p-j}, \hbox { for } n\ge p. \end{aligned}$$
(33)

It is well known that the general solution of the non-homogeneous equation (30), is written in the following form, \(\displaystyle y_{np+j}=y_{np+j}^{<h>}+y_{np+j}^{<p>}\), (see for instance [12], and references therein). In summary, applying Expressions (32)–(33), we can formulate our main result, concerning the solutions of Eq. (2), as follows.

Theorem 3.3

Let us consider the difference equations (2) and suppose that the coefficients \(a_0(n)\), \(a_1(n)\) are periodic of period \(p\ge 2\). Then, for every \( j=0,...,p-1 \), the combinatorial formulas of the solutions \(\{y_{np+j}\}_{n\ge p}\) of Eq. (2), are given by,

$$\begin{aligned} y_{np+j}=y_{np+j}^{<h>}+y_{np+j}^{<p>},\;\;\;\;\hbox { for every }\;\;\;\; j=0,...,p-1, \end{aligned}$$

where

$$\begin{aligned} \left\{ \begin{aligned}&y_{np+j}^{<h>}=c_2\rho (n-p+2,2)y_{(p-2)p+j}+\rho (n-p+3,2)y_{(p-1)p+j}, \\&y_{np+j}^{<p>}=\sum \limits _{i=2}^{n-p+2}\rho (n-p-i+4,2)\varphi ^{(i-1)}_{p-j}. \end{aligned} \right. \end{aligned}$$

Let \( \lambda _1\), \(\lambda _2 \) be the roots of the polynomial \( P(z)=z^{2}-c_1z-c_2\), where the coefficients \(c_1\), \(c_2\) are as in (19). Then, the analytic formulas of the solutions \(\{y_{np+j}\}_{n\ge p}\) of Eq. (2), are given by,

$$\begin{aligned} y_{np+j}=y_{np+j}^{<h>}+y_{np+j}^{<p>},\;\;\;\;\hbox { for every }\;\;\;\;j=0,...,p-1, \end{aligned}$$

such that, for \(\lambda _1\not = \lambda _2\), we have,

$$\begin{aligned} \left\{ \begin{aligned}&y_{np+j}^{<h>}=\sum \limits _{i=1}^{2}\dfrac{c_2\lambda _iy_{(p-2)p+j}+\lambda _i^2y_{(p-1)p+j}}{P'(\lambda _i)}\lambda _i^{n-p}, \\&y_{np+j}^{<p>}=\sum \limits _{i=2}^{n-p+2}\left[ \dfrac{\lambda _1^{n-p-i+3}}{P'(\lambda _1)}+\dfrac{\lambda _2^{n-p-i+3}}{P'(\lambda _2)} \right] \varphi ^{(i-1)}_{p-j}, \end{aligned} \right. \end{aligned}$$

and for \(\lambda _1 = \lambda _2=\lambda \), we have,

$$\begin{aligned} \left\{ \begin{aligned}&y_{np+j}^{<h>}=\left[ (n-p+1)c_2\lambda y_{(p-2)p+j}+((n-p)\lambda ^2+c_1\lambda )y_{(p-1)p+j} \right] \lambda ^{n-p-1},\\&y_{np+j}^{<p>} = \sum \limits _{i=2}^{n-p+2}(n-p-i+3)\lambda ^{n-p-i+2}\varphi ^{(i-1)}_{p-j}, \end{aligned} \right. \end{aligned}$$

where the scalar \(\varphi _{j}^{(k)}\) given by (26), are the entries of \( H^{*}_k=H_{p+k}-c_1H_{p-1+k}-c_2H_{p-2+k} \), the vector column (21).

To better visualize our main result, we will consider the following illustrative numerical example.

Example 3.4

Let us consider the difference equations (2) and suppose that the coefficients \(a_0(n)\), \(a_1(n)\) are periodic of period \(p=3\), with a given sequence \( (g_n)_{n>0} \) and initial conditions \( y_0,\;y_1 \). Suppose that for the related matrix representation (3), we have,

$$\begin{aligned} A(0)=\begin{pmatrix} 1 &{} -2 &{} 0 \\ 1 &{} 0 &{} 0 \\ 0 &{} 1 &{} 0 \end{pmatrix},\;\; A(1)=\begin{pmatrix} -1 &{} 3 &{} 0 \\ 1 &{} 0 &{} 0 \\ 0 &{} 1 &{} 0 \end{pmatrix},\;\; A(2)=\begin{pmatrix} 4 &{} 2 &{} 0 \\ 1 &{} 0 &{} 0 \\ 0 &{} 1 &{} 0 \end{pmatrix}. \end{aligned}$$

Using the algorithm (12), we can see that the scalars \(\alpha _j^{(h)}\) and \(\beta _j^{(h)}\) satisfy the following relations:

$$\begin{aligned} \left\{ \begin{aligned}&\alpha _{j}^{(h)}=\alpha _{j-1}^{(h-1)}a_0(p-1-h)+\alpha _{j-2}^{(h-2)}a_1(p-h), \\&\beta _{j}^{(h)}=\alpha _{j-1}^{(h-1)}a_1(p-1-h),\\&\alpha _{-1}^{(h-2)}=1,\;\alpha _{-2}^{(h-2)}=0\;\hbox { for all}\;h\ge 0. \end{aligned} \right. \end{aligned}$$

Therefore, we get, \( C(0)=\begin{pmatrix} \alpha _{0}^{(0)} &{} \beta _{0}^{(0)} &{} 0 \\ 1 &{} 0 &{} 0 \\ 0 &{} 1 &{} 0 \end{pmatrix}=\begin{pmatrix} 4 &{} 2 &{} 0 \\ 1 &{} 0 &{} 0 \\ 0 &{} 1 &{} 0 \end{pmatrix},\; C(1)=\begin{pmatrix} \alpha _{1}^{(1)} &{} \beta _{1}^{(1)} &{} 0 \\ \alpha _{0}^{(1)} &{} \beta _{0}^{(1)} &{} 0 \\ 1 &{} 0 &{} 0 \end{pmatrix}=\begin{pmatrix} -2 &{} 12 &{} 0 \\ -1 &{} 3 &{} 0 \\ 1 &{} 0 &{} 0 \end{pmatrix} \) and

$$\begin{aligned} B=\begin{pmatrix} \alpha _{2}^{(2)} &{} \beta _{2}^{(2)} &{} 0 \\ \alpha _1^{(2)} &{} \beta _1^{(2)} &{} 0 \\ \alpha _0^{(2)} &{} \beta _0^{(2)} &{} 0 \end{pmatrix}=\begin{pmatrix} 10 &{} 4 &{} 0 \\ 2 &{} 2 &{} 0 \\ 1 &{} -2 &{} 0 \end{pmatrix}. \end{aligned}$$

We infer that \( c_1,\;c_2 \) are given by \( c_1=\alpha _{2}^{(2)}+\beta _1^{(2)}=12 \) and \( c_2=\alpha _{1}^{(2)}\beta _2^{(2)}-\alpha _{2}^{(2)}\beta _1^{(2)}=-12 \). Thus, we obtain,

$$\begin{aligned} P(z)=z^{2}-c_1z-c_2=(z-\lambda _1)(z-\lambda _2), \end{aligned}$$

where \( \lambda _1=6-3\sqrt{3} \), \( \lambda _2=6+3\sqrt{3} \), \( P^{'}(\lambda _1)=-6\sqrt{3} \) and \( P^{'}(\lambda _2)=6\sqrt{3} \). Moreover, with the aid of Expression (6), we derive that the vectors columns \(Y_6=\begin{pmatrix} y_5 \\ y_4 \\ y_3 \end{pmatrix}\) and \(Y_9=\begin{pmatrix} y_8 \\ y_7 \\ y_6 \end{pmatrix}\) are given by,

\( Y_6=BY_3+U_6+C(0)U_5+C(1)U_4=\begin{pmatrix} 44y_1+20y_0 \\ 10y_1+4y_0 \\ 2y_1+2y_0 \end{pmatrix}+\begin{pmatrix} g_5+4g_4-2g_3+10g_2 \\ g_4-g_3+2g_2 \\ g_3+g_2 \end{pmatrix}, \)

and \( Y_9= B^{2}Y_3+U_9+C(0)U_8+C(1)U_7+BU_6+B[ C(0)U_5+C(1)U_4].\) Then, for \( j=0,1,2 \) and \( n\ge 3 \), the homogeneous solution is

$$\begin{aligned}{} & {} y_{3n+j}^{<h>}=\frac{2}{\sqrt{3}}\left( (6-3\sqrt{3})y_{3+j}-(5-3\sqrt{3})y_{6+j}\right) (6-3\sqrt{3})^{n-3} \\{} & {} \quad \;\;\;\;\;\;\;\;\;\;\;\; +\frac{2}{\sqrt{3}} \left( (5+3\sqrt{3})y_{6+j}-(6+3\sqrt{3})y_{3+j}\right) (6+3\sqrt{3})^{n-3}. \end{aligned}$$

Furthermore, using Expression (32), we get the following particular solution,

$$\begin{aligned} y_{3n+j}^{<p>}=\dfrac{1}{6\sqrt{3}}\sum \limits _{i=2}^{n-1} \left[ (6+3\sqrt{3})^{n-i}-(6-3\sqrt{3})^{n-i} \right] \varphi _{3-j}^{(i-1)}, \end{aligned}$$

where the \( \varphi ^{(k)}_j \) are such that \(H^{*}_k=\begin{pmatrix}\varphi ^{(k)}_1 \\ \varphi ^{(k)}_2 \\ \varphi ^{(k)}_3 \end{pmatrix}\). More precisely, we have,

\(H^{*}_k=\left( B^{2}-c_1B-c_2I_p\right) \left( \sum \limits _{i=0}^{p+k-4}B^{i}D_{k-2-i}\right) +\left( B-c_1I_p\right) D_{k-1}+D_k.\)

Since \( D_k=\begin{pmatrix} g_{3(k+3)-1}+4g_{3(k+3)-2}-2g_{3(k+3)-3} \\ g_{3(k+3)-2}-g_{3(k+3)-3} \\ g_{3(k+3)-3} \end{pmatrix} \), the explicit formula of the \( \varphi ^{(k)}_j \) is as follows:

$$\begin{aligned} \varphi ^{(k)}_j = z_j^{(k)}+v_j^{(k)}+ \sum \limits _{h=j-2}^{p-2} \alpha _{h-j+1}^{(h)}g_{(p+k)p-2-h} \;\;\;\hbox {for}\;\;\;j=0,1,2, \end{aligned}$$

and \(\alpha _{j}^{(h)}\), \( z_j^{(k)},\;v_j^{(k)} \) are given by (23), (24) and (25).

4 Solutions of Eq. (2)—second approach

In this section we will provide another approach for resolving Eq. (2). We need to use some results established in [8], regarding companion matrices. That is, let us get back to equation (6), namely,

$$\begin{aligned} Y_{kp}=B^{k-1}Y_{p}+\sum \limits _{i=0}^{k-2}B^{i}U_{(k-i)p}+\sum \limits _{i=0}^{k-2}B^{i}\sum \limits _{h=0}^{p-2}C(h)U_{(k-i)p-1-h},\;\;\hbox { for }\;\;\;k\ge 2. \end{aligned}$$

The former equation can be written under the form,

$$\begin{aligned} Y_{kp}=B^{k-1}Y_{p}+\sum \limits _{i=0}^{k-2}B^{i}D_{k-i-p}\;\;\hbox { for }\;\;\;k\ge 2, \end{aligned}$$

where \(D_k=U_{(p+k)p}+\sum \limits _{h=0}^{p-2}C(h)U_{(p+k)p-1-h}\) is the matrix exhibited by the explicit formula (22). By appealing the expression of \(B^k\) (\(k\ge 1\)), established in Expression (13), we have

$$\begin{aligned} B^k=\begin{pmatrix} \theta _{1}^{(k)} &{} \gamma _{1}^{(k)} &{} 0 &{} \cdots \\ \theta _{2}^{(k)} &{} \gamma _{2}^{(k)} &{} 0 &{} \cdots \\ \vdots &{} \vdots &{} \vdots \\ \theta _{p}^{(k)} &{} \gamma _{p}^{(k)} &{} 0 &{} \cdots \end{pmatrix}, \end{aligned}$$

where the entries \( \theta _{j}^{(k)}\), \( \gamma _{j}^{(k)}\) of the matrix \(B^k\) are defined as follows. For \(k=1\), we get

$$\begin{aligned} \left\{ \begin{aligned}&\theta _{j}^{(1)}=\alpha _{p-j}^{(p-1)}\\&\gamma _{j}^{(1)}=\beta _{p-j}^{(p-1)} \end{aligned} \right. \;\; \hbox {for} \; j=1,2,...,p, \end{aligned}$$

where the \(\;\alpha _{j}^{(h)}\), \(\;\beta _{j}^{(h)}\) are computed using Eq. (12). For \(k=2\), we have

$$\begin{aligned} \left\{ \begin{aligned}&\theta _{j}^{(2)}= \theta _{j}^{(1)}\theta _{1}^{(1)}+\gamma _{j}^{(1)}\theta _{2}^{(1)}, \\&\gamma _{j}^{(2)}=\theta _{j}^{(1)}\gamma _{1}^{(1)}+\gamma _{j}^{(1)}\gamma _{2}^{(1)}, \end{aligned} \right. \;\;\;\;\;\;\hbox { for } j=1,2,...,p. \end{aligned}$$
(34)

For \( k\ge 3 \), we acquire

$$\begin{aligned} \left\{ \begin{aligned}&\theta _{j}^{(k)}= r_{k-1}\theta _{j}^{(1)} +s_{k-1}\gamma _{j}^{(1)}, \\&\gamma _{j}^{(k)}=t_{k-1}\theta _{j}^{(1)} +u_{k-1} \gamma _{j}^{(1)}, \end{aligned} \right. \;\;\;\;\;\; \hbox { for } j=1,2,...,p, \end{aligned}$$
(35)

such that

$$\begin{aligned} \left\{ \begin{aligned}&r_n=\theta _{1}^{(1)}\rho (n+1,2)+c_2\rho (n,2), \\&s_n=\theta _{2}^{(1)}\rho (n+1,2), \\&t_n=\gamma _{1}^{(1)}\rho (n+1,2),\\&u_n=\gamma _{2}^{(1)}\rho (n+1,2)+c_2 \rho (n,2), \end{aligned} \right. \end{aligned}$$
(36)

where \(\rho (n,2)\) is the combinatorial Expression (16). Moreover, for \( 0\le i\le k-2 \), we come by \( B^iD_{k-p-i}=\begin{pmatrix} x_1^{(i)}\\ x_2^{(i)}\\ \vdots \\ x_p^{(i)} \end{pmatrix},\) where

$$\begin{aligned} \left\{ \begin{aligned}&x_j^{(i)}= \sum \limits _{h=-1}^{p-2}\left[ \theta _{j}^{(i)}\alpha _{h}^{(h)}+\gamma _{j}^{(i)}\alpha _{h-1}^{(h)}\right] g_{(k-i)p-2-h}\;\;\;\hbox { for }\;\;i\ne 0, \\&x_j^{(0)}=\sum \limits _{h=j-2}^{p-2}\alpha _{h-j+1}^{(h)}\; g_{kp-2-h} \end{aligned} \right. \end{aligned}$$
(37)

with \(\theta _{j}^{(k)}\), \(\gamma _{j}^{(k)}\) are as in (34)–(35) and the \(\alpha _{k}^{(h)}\) are as in (12). In addition, we consider the entries \(y_{kp-j}\) of the matrix equation \( Y_{kp}=B^{k-1}Y_{p}+\sum \limits _{i=0}^{k-2}B^{i}D_{k-i-p}\). Finally, we can formulate our main result, concerning the solutions of Eq. (2), as follows.

Theorem 4.1

With the same notation as above, for every \( j=1,2,...,p \), the solutions of Eq. (2) are given by,

$$\begin{aligned} y_{kp-j}=\theta _{j}^{(k-1)}y_{p-1}+\gamma _{j}^{(k-1)}y_{p-2}+ \sum \limits _{i=0}^{k-2}x_j^{(i)}, \; \hbox {for} \; k\ge 2, \end{aligned}$$
(38)

where \(\theta _{j}^{(k)}\), \(\gamma _{j}^{(k)}\) are given by (34)–(35) and (36), the \(\alpha _{k}^{(h)}\) are as in (12) and \(x_j^{(i)}\) are given by (37).

Following Formulas (35)–(36), we show that Expression (38) of the combinatorial solutions of Eq. (2) are expressed in terms of the \(\rho (n,2)\) given by (16). It was also established that (17) and (18) are the analytic expressions of \(\rho (n,2)\), when the polynomial \(P(z)=z^2-c_1z-c_2\) has simple roots or a unique root, respectively. More precisely, when the two roots of the polynomial \(P(z)=z^2-c_1z-c_2\) are simple, by substituting the analytical expressions of \(\rho (n,2)\) and \(\rho (n+1,2)\), given by (17), in Expression (36), we obtain the analytical form of the solutions of Eq. (2). More precisely, we have the following result.

Proposition 4.2

With the same notation as above, Suppose that the polynomial \(P(z)=z^2-c_1z-c_2\) owns simple roots \(\lambda _1\), \(\lambda _2\). Then, the solutions \(y_{kp-j}\) of Eq. (2) are given by,

$$\begin{aligned} y_{kp-j}=\theta _{j}^{(k-1)}y_{p-1}+\gamma _{j}^{(k-1)}y_{p-2}+ \sum \limits _{i=0}^{k-2}x_j^{(i)},\; \; \end{aligned}$$

for \( j=1,2,...,p \), where \(x_j^{(i)}\) are given by (37), and \(\theta _{j}^{(k)}\), \(\gamma _{j}^{(k)}\) are as in (34)–(35) such that,

$$\begin{aligned} \left\{ \begin{aligned}&r_n=\frac{\theta _{1}^{(1)}\lambda _1+c_2}{P'(\lambda _1)} \lambda _1^{n-1}+\frac{\theta _{1}^{(1)}\lambda _2+c_2}{P'(\lambda _2)} \lambda _2^{n-1},\\&s_n= \frac{\theta _{2}^{(1)}}{P'(\lambda _1)} \lambda _1^{n}+\frac{\theta _{2}^{(1)}}{P'(\lambda _2)} \lambda _2^{n},\\&t_n= \frac{\gamma _{1}^{(1)}}{P'(\lambda _1)} \lambda _1^{n}+\frac{\gamma _{1}^{(1)}}{P'(\lambda _2)} \lambda _2^{n},\\&u_n= \frac{\gamma _{2}^{(1)}\lambda _1+c_2}{P'(\lambda _1)} \lambda _1^{n-1}+\frac{\gamma _{2}^{(1)} \lambda _2+c_2}{P'(\lambda _2)} \lambda _2^{n-1}. \end{aligned} \right. \end{aligned}$$
(39)

Now, suppose that the two roots of the polynomial \(P(z)=z^2-c_1z-c_2\) are equal, then a substitution of the analytic Expression (18) of the \(\rho (n,r)\) in Expressions (36), allows us to obtain the following analytic form for the solution of Eq. (2).

Proposition 4.3

With the same notation as above, Suppose that the polynomial \(P(z)=z^2-c_1z-c_2\) owns simple roots \(\lambda _1\), \(\lambda _2\). Then, the solutions \(y_{kp-j}\) of Eq. (2) are given by,

$$\begin{aligned} y_{kp-j}=\theta _{j}^{(k-1)}y_{p-1}+\gamma _{j}^{(k-1)}y_{p-2}+\sum \limits _{i=0}^{k-2}x_j^{(i)},\; \end{aligned}$$

for \( j=1,2,...,p \), where \(x_j^{(i)}\) are given by (37), and \(\theta _{j}^{(k)}\), \(\gamma _{j}^{(k)}\) are as in (34)–(35) such that,

$$\begin{aligned} \left\{ \begin{aligned}&r_n=\left[ \theta _{1}^{(1)}n\lambda +c_2(n-1) \right] \lambda ^{n-2},\\&s_n= \theta _{2}^{(1)}n\lambda ^{n-1},\\&t_n= \gamma _{1}^{(1)}n\lambda ^{n-1},\\&u_n= \left[ \gamma _{2}^{(1)}n\lambda +c_2 (n-1) \right] \lambda ^{n-2}. \end{aligned} \right. \end{aligned}$$
(40)

5 Study of the special case \(p=2\)

In this section, we focus our study to the special case when \(p=2\). The calculation of the powers of B can be exhibited explicitly in this case, which allows us to obtain handled expressions of the solutions of (2). That is, let us consider the equation (2), such that the coefficients \(a_0(n)\), \(a_1(n)\) are periodic of period \(p=2\), viz \(\displaystyle y_n=a_0(n)y_{n-1}+a_1(n)y_{n-2}+g_n,\) where \(a_0(n+2)=a_0(n)\), \(a_1(n+2)=a_1(n)\). Recall that the matrix representation (3) in this case is, \(\displaystyle Y_{n+1}=A(n)Y_n+U_{n+1},\) with \( Y_n=\begin{pmatrix} y_{n-1} \\ y_{n-2} \end{pmatrix} \), \( A(n)=\begin{pmatrix} a_0(n) &{} a_1(n) \\ 1 &{} 0 \end{pmatrix} \) and \( U_{n+1}=\begin{pmatrix} g_n \\ 0 \end{pmatrix} \). Consequently, with the aid of the results of subsection 2.2, notably Expression (12), related to the algorithms for calculating the matrices C(h) and the powers of the matrix \(B =C(p-1 )\), we have \( C(0)=A(1) \), \( B=\begin{pmatrix} \alpha _1^{(1)} &{} \beta _1^{(1)} \\ \alpha _0^{(1)} &{} \beta _0^{(1)} \end{pmatrix}=\begin{pmatrix} a_0(0)a_0(1)+a_1(1) &{} a_1(0)a_0(1) \\ a_0(0) &{} a_1(0) \end{pmatrix} \) and

$$\begin{aligned} Y_{2k}=B^{k-1}Y_{2}+\sum \limits _{i=0}^{k-2}B^{i}\left[ U_{2(k-i)}+C(0)U_{2(k-i)-1} \right] . \end{aligned}$$

The characteristic polynomial of the matrix B is \(P_B(z)=z^2-d_1z-d_2\) with

$$\begin{aligned} \left\{ \begin{aligned}&d_1=\alpha _1^{(1)} + \beta _0^{(1)}=a_0(0)a_0(1)+a_1(0)+a_1(1), \\&d_2=\alpha _0^{(1)}\beta _1^{(1)}-\alpha _1^{(1)} \beta _0^{(1)}=-a_1(0)a_1(1). \end{aligned} \right. \end{aligned}$$

To calculate the powers \( B^n \) for \( n\ge 2 \), we use the Fibonacci–Horner decomposition (for more details, see [6]). Thus, we have,

$$\begin{aligned}{} & {} B^n=u_nB_0+u_{n-1}B_1\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\; \\ {}{} & {} \;\;\;\;\;=\rho (n+2,2)I_2+\rho (n+1,2)(B-d_1I_2), \end{aligned}$$

with \( \rho (1,2)=0 \), \( \rho (2,2)=1 \), and

$$\begin{aligned} \rho (n,2)=\sum \limits _{k_0+2k_1=n-2}\dfrac{(k_0+k_1)!}{k_0!k_1!}d_1^{k_0}d_2^{k_1} \;\;\;\;\;\;\;\;\;(n>2) \end{aligned}$$

For all \( n\ge 0 \), we put

$$\begin{aligned} B^n=\begin{pmatrix} \theta _{1}^{(n)} &{} \gamma _{1}^{(n)} \\ \theta _{2}^{(n)} &{} \gamma _{2}^{(n)} \end{pmatrix}, \end{aligned}$$

where

$$\begin{aligned} \left\{ \begin{aligned}&\theta _{1}^{(0)}=1,\;\;\theta _{2}^{(0)}=0, \\&\gamma _{1}^{(0)}=0,\;\;\gamma _{2}^{(0)}=1, \end{aligned} \right. \;\;\; \hbox {and} \left\{ \begin{aligned}&\theta _{1}^{(1)}=a_0(0)a_0(1)+a_1(1),\;\;\theta _{2}^{(1)}=a_0(0), \\&\gamma _{1}^{(1)}=a_1(0)a_0(1),\;\;\gamma _{2}^{(1)}=a_1(0). \end{aligned} \right. \end{aligned}$$

Then, for every \( n\ge 2 \), we have,

$$\begin{aligned} \left\{ \begin{aligned}&\theta _{1}^{(n)}=\rho (n+2,2)+\rho (n+1,2)[\theta _{1}^{(1)}-d_1], \\&\theta _{2}^{(n)}=\rho (n+1,2)\theta _{2}^{(1)}, \\&\gamma _{1}^{(n)}=\rho (n+1,2)\gamma _{1}^{(1)}, \\&\gamma _{2}^{(n)}=\rho (n+2,2)+\rho (n+1,2)[\gamma _{2}^{(1)}-d_1]. \end{aligned} \right. \end{aligned}$$

For this special case, Expression (6) takes the form,

$$\begin{aligned} Y_{2k}=B^{k-1}Y_{2}+\sum \limits _{i=0}^{k-2}B^{i}\left[ U_{2(k-i)}+C(0)U_{2(k-i)-1} \right] , \end{aligned}$$

where

$$\begin{aligned} U_{2(k-i)}+C(0)U_{2(k-i)-1}=\begin{pmatrix} g_{2(k-i)-1}+a_0(1)g_{2(k-i)-2} \\ g_{2(k-i)-2} \end{pmatrix}. \end{aligned}$$

Summarizing, we get the following result,

Theorem 5.1

Consider the equation (2) of variable coefficients \(a_0(n)\), \(a_1(n)\). Suppose that \(a_0(n)\), \(a_1(n)\) are periodic of period \(p=2\). Then, the solutions of Equation (2) are given by,

$$\begin{aligned} \left\{ \begin{aligned}&y_{2k-1}=\theta _{1}^{(k-1)}y_1+\gamma _{1}^{(k-1)}y_0+\sum \limits _{i=0}^{k-2}\theta _{1}^{(i)}\left[ g_{2(k-i)-1}+a_0(1)g_{2(k-i)-2} \right] + \gamma _{1}^{(i)}g_{2(k-i)-2}, \\&y_{2k-2}=\theta _{2}^{(k-1)}y_1+\gamma _{2}^{(k-1)}y_0+\sum \limits _{i=0}^{k-2}\theta _{2}^{(i)}\left[ g_{2(k-i)-1}+a_0(1)g_{2(k-i)-2} \right] + \gamma _{2}^{(i)}g_{2(k-i)-2}. \end{aligned} \right. \end{aligned}$$

To illustrate the above result of Theorem (), we explore the following numerical example.

Example 5.2

Let us consider Eq. (2) given by,

$$\begin{aligned} y_n(x)=cos(x+n\pi )y_{n-1}(x)+sin(x+n\pi )y_{n-2}(x)+g(n), \end{aligned}$$
(41)

for a fixed real number x, where the initial conditions \( y_{0}(x)\), \(y_{1}(x) \) and the function g(n) are given. We have,

$$\begin{aligned} A(0)=\begin{pmatrix} cos(x) &{} sin(x) \\ 1 &{} 0 \end{pmatrix}, A(1)=\begin{pmatrix} -cos(x) &{} -sin(x) \\ 1 &{} 0 \end{pmatrix} \end{aligned}$$

and

$$\begin{aligned} B=\begin{pmatrix} -cos^2(x) -sin(x) &{} -cos(x) sin(x) \\ cos(x) &{} sin(x) \end{pmatrix}. \end{aligned}$$

The characteristic polynomial associated to B is

$$\begin{aligned} P_B(z)=z^2+cos^2(x)z-sin^2(x)=\left( z-sin^2(x)\right) \left( z+1\right) . \end{aligned}$$

Using the Fibonacci-Horner decomposition, we obtain,

$$\begin{aligned} B^n=\rho (n+2,2)I_2+\rho (n+1,2)(B+cos^2(x)I_2), \end{aligned}$$

with

$$\begin{aligned} \rho (n,2)=\dfrac{sin^{2(n-1)}(x)-(-1)^{n-1}}{sin^2(x)+1}. \end{aligned}$$

Then, for \( n\ge 2 \), we have,

$$\begin{aligned} B^n=\begin{pmatrix} \theta _{1}^{(n)} &{} \gamma _{1}^{(n)} \\ \theta _{2}^{(n)} &{} \gamma _{2}^{(n)} \end{pmatrix}, \end{aligned}$$

where

$$\begin{aligned} \left\{ \begin{aligned}&\theta _{1}^{(n)}=\rho (n+2,2)-\rho (n+1,2)sin(x),\\&\theta _{2}^{(n)}=\rho (n+1,2)cos(x), \\&\gamma _{1}^{(n)}=-\rho (n+1,2)cos(x)sin(x), \\&\gamma _{2}^{(n)}=\rho (n+2,2)+\rho (n+1,2)[sin(x)+cos^2(x)]. \end{aligned} \right. \end{aligned}$$

and the solutions of Eq. (41) are as follows:

$$\begin{aligned} \left\{ \begin{aligned}&y_{2k-1}(x)=\theta _{1}^{(k-1)}y_1(x)+\gamma _{1}^{(k-1)}y_0(x)+\sum \limits _{i=0}^{k-2}\theta _{1}^{(i)} \Delta (k,i,\cos (x)) + \gamma _{1}^{(i)}g_{2(k-i)-2}, \\&y_{2k-2}(x)=\theta _{2}^{(k-1)}y_1(x)+\gamma _{2}^{(k-1)}y_0(x)+\sum \limits _{i=0}^{k-2}\theta _{2}^{(i)} \Delta (k,i,\cos (x))+ \gamma _{2}^{(i)}g_{2(k-i)-2}, \end{aligned} \right. \end{aligned}$$

where \(\Delta (k,i,\cos (x))= g_{2(k-i)-1}-\cos (x)g_{2(k-i)-2}\).

6 Conclusion and discussion

Thanks to our approaches, we have succeeded in decomposing the nonhomogeneous difference equation (2), which has periodic variable coefficients with period \( p \ge 2 \), into a family of p nonhomogeneous equations with constant coefficients. These equations were resolved using a matrix technique developed in [12]. Moreover, our approaches based on some auxiliary results established in Section 2 allows us to establish combinatorial and analytic expressions of the solutions for Eq. (2), with periodic coefficients.

To the best of our knowledge, our approaches are not common in the literature. The process of linearization of Eq. (2), permits us to get around the problem by studying nonhomogeneous linear difference equations with constant coefficients. More precisely, this process made it possible to reduce the result of nonhomogeneous equations with periodic coefficients (2), to that of nonhomogeneous linear difference equations with constant coefficients. Thereafter, the method of [12] allows us to provide explicit formulas for the solutions of Eq. (2).

We would like to point out that, the nonhomogeneous difference equations of order r, namely, Eq. (1), with periodic coefficients \(a_j(n)\) (\(0\le j\le r-1\)), is under study. The two references [2, 3] seem to be useful for studying the higher order Eq. (1).