2
$\begingroup$

I want to solve a recurrence equation that has boundary conditions on both sides:

$a[0]= 1$

$a[n]= 10$

$a[i] = a[i-1]-a[i+1]\quad \forall i \in \{1, \ldots, n-1\}$

This should be a well defined system with n+1 equations and n+1 unknowns.

I tried:

RSolve[{a[n] == a[n - 1] - a[n + 1], a[0] == 1,a[n] == 10}, a[n], n]

But Mathematica says the system is overdetermined:

RSolve::overdet: There are fewer dependent variables than equations, so the system is overdetermined.

The issue is likely that I have not encoded that $\forall i \in \{1, \ldots, n-1\}$ we have a[i] == a[i - 1] - a[i + 1] and only for the very last i: $i=n$ we have a[n] == 10, right? How can I encode this in RSolve?

$\endgroup$
1
  • 1
    $\begingroup$ why not the boring Solve after creating a Table with values? You can solve for all the a[i] $\endgroup$
    – bmf
    Commented Apr 28, 2022 at 19:57

2 Answers 2

7
$\begingroup$

Your code uses n in two roles: one for the defining recursion relation, and the other for the boundary condition. This confuses Mathematica (and the casual human reader, to boot.) Use different symbols for each of these two roles and it works a treat, yielding a general solution that works for all boundary values of n.

RSolve[{a[i] == a[i - 1] - a[i + 1], a[0] == 1, a[n] == 10}, a[i], i];
Simplify[%, Assumptions -> Element[n, Integers]]

(* {{a[i] -> ( 2^-i (5 2^(1 + n) (-1 + Sqrt[5])^i - (-1 - Sqrt[5])^n (-1 + Sqrt[5])^i + (-1 - Sqrt[5])^i (-5 2^(1 + n) + (-1 + Sqrt[5])^n)))/
             ((-1 + Sqrt[5])^n + (-1)^(1 + n) (1 + Sqrt[5])^n)}} *)

enter image description here

$\endgroup$
5
$\begingroup$
Clear["Global`*"]

Format[f[n_, k_]] := TraditionalForm[Subscript[f, n][k]]

Prepend[(tab =
    Table[{n, f[n, k_] =
       RSolveValue[{a[k] == a[k - 1] - a[k + 1],
          a[0] == 1, a[n] == 10}, a[k], k] // FullSimplify,
      If[(f[n, 0] == 1 && f[n, n] == 10) // Simplify,
       Style["✓", 24, Darker@Green],
       Style["X", 24, Red]]}, {n, 1, 10}]),
  {n, StringForm["``", f[n, k]],
   StringForm["`` &&\n``",
    f[n, 0] == 1, f[n, n] == 10]}] //
 Grid[#, Frame -> All, Alignment -> {Center, Center}] &

enter image description here

$\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.