# Use the RSolve command of Mathematica to solve difference equations in matrix form？

For example, if $$A$$ is a matrix, the following is its difference equation representation.

How can I rewrite the code to use the RSolve command correctly?

A = {{0, -1/0.2}, {1/0.01, -1/(22 0.01)}};
RSolve[{A[n + 1] - 2 A[n] == 1, A[0] == 1}, A[n], n]

• You can not define the variable A={...} that you are searching. Feb 26, 2023 at 8:28
• @DanielHuberan Can $RSolve$ command solve the difference equation in matrix form？ Feb 26, 2023 at 9:23
• @chenchen The matrix difference equation should be A[n + 1] - 2 A[n] == IdentityMatrix[2] I think Feb 26, 2023 at 9:53
• @chenchen You got answer to this question some days ago: Matrix difference equation Feb 26, 2023 at 9:58

\$Version

(* "13.2.1 for Mac OS X ARM (64-bit) (January 27, 2023)" *)

ClearAll["Global*"]


Rationalize A[0]

A[0] = {{0, -1/0.2}, {1/0.01, -1/(22 0.01)}} // Rationalize;


Define A[n] recursively

A[n_Integer?Positive] := A[n] = 2*A[n - 1] + IdentityMatrix[2]


Generate a sequence of matrices

MatrixForm /@ (seq = (A /@ Range[10]))


Use FindSequenceFunction for each matrix position to find the general solution

(A2[n_] = Partition[
FindSequenceFunction[#, n] & /@
Transpose[Flatten /@ seq],
2] // Simplify) // MatrixForm


Comparing the general solution with the recursive definition over a broader range

And @@ Table[A[n] == A2[n], {n, 0, 100}]

(* True *)


EDIT: For a general 2x2 initial matrix

Format[a[n__]] := Subscript[a, Row[{n}]]

\[DoubleStruckCapitalA][0] = Array[a, {2, 2}];

\[DoubleStruckCapitalA][n_Integer?Positive] :=
\[DoubleStruckCapitalA][n] =
2*\[DoubleStruckCapitalA][n - 1] + IdentityMatrix[2]

seq = (\[DoubleStruckCapitalA] /@ Range[7]) // Simplify;

(\[DoubleStruckCapitalA]2[n_] =
Partition[FindSequenceFunction[#, n] & /@
Transpose[Flatten /@ seq], 2] // Simplify) //
MatrixForm


Verifying that the general solution agrees with the recursive definition over a broad range

And @@ Table[\[DoubleStruckCapitalA][n] ==
\[DoubleStruckCapitalA]2[n], {n, 0, 100}] // Simplify

(* True *)


Comparing with the initial result,

repl = Thread[
Flatten[\[DoubleStruckCapitalA][0]] ->
Flatten[Rationalize[{{0, -1/0.2}, {1/0.01, -1/(22 0.01)}}]]]


A2[n] === Simplify[\[DoubleStruckCapitalA]2[n] /. repl]

(* True *)


EDIT 2: Using RSolveValue indirectly

RSolveValue[{A[n + 1] - 2 A[n] == 1, A[0] == A0}, A[n], n]

(* -1 + 2^n + 2^n A0 *)


Converting this result to matrices

A0 = Array[a, {2, 2}];

(A[n_] = 2^n*A0 + 2^n*IdentityMatrix[2] - IdentityMatrix[2]) //
MatrixForm
`

This is identical to \[DoubleStruckCapitalA]2[n]