0
$\begingroup$

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]
$\endgroup$
4
  • $\begingroup$ You can not define the variable A={...} that you are searching. $\endgroup$ Commented Feb 26, 2023 at 8:28
  • $\begingroup$ @DanielHuberan Can $RSolve$ command solve the difference equation in matrix form? $\endgroup$
    – chen chen
    Commented Feb 26, 2023 at 9:23
  • $\begingroup$ @chenchen The matrix difference equation should be A[n + 1] - 2 A[n] == IdentityMatrix[2] I think $\endgroup$ Commented Feb 26, 2023 at 9:53
  • 1
    $\begingroup$ @chenchen You got answer to this question some days ago: Matrix difference equation $\endgroup$ Commented Feb 26, 2023 at 9:58

1 Answer 1

3
$\begingroup$
$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]))

enter image description here

Use FindSequenceFunction for each matrix position to find the general solution

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

enter image description here

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

enter image description here

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)}}]]]

enter image description here

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

enter image description here

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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