[Corrected equations and added simple example]

Can you solve a system of (loosely) coupled recurrence relations like this in Mathematica somehow?

{A[k] ==1+((n-k-2)/n) A[k+1] +(2/n) B[k+1] + (k/n) (A[0]), 
 B[k]==1+((n-k-1)/n) B[k+1] + (k/n) A[0]}

We want to solve it for $A[0]$ as a closed form function of $n$.

$A[k]$ is defined for $0 \leq k \leq n-2$ and $B[k]$ is defined for $1 \leq k \leq n-1$.

Version 8 doesn't do anything useful but I suspect I am not asking it in the right way.

As a simple example, if you set $n=3$ then you get four simulataneous equations.

A[0] == 1 + (2/3)*B[1] + (1/3)*A[1]
B[1] == 1 + (1/3)*A[0] + (1/3)*B[2]
B[2] == 1 + (2/3)*A[0]
A[1] == 1 + (2/3)*B[2] + (1/3)*A[0]

Solving for $A[0]$ gives you $33/5$ I believe. To start things off, how do you get Mathematica to do this?

Update. If you just take the second recurrence alone.

B[k]==1+((n-k-1)/n) B[k+1] + (k/n) A[0]

How can you get Mathematica to give a sensible solution for $B[k]$ in terms of $n$ and $A[0]$? It seems Rsolve ought to be able to do this. I even tried

RSolve[{B[k] == 1 + ((n - k - 1)/n) B[k + 1] + ((k)/n) (A[0]), 
  B[n - 1] == k A[0]/n}, B[k], k]

which should be identical. However this now gives an empty solution with the following warning.

RSolve::bvnul: For some branches of the general solution, the given boundary conditions lead to an empty solution.

I would like to tell Mathematica to only try to solve it for the defined range of $k$. Is that possible?

  • $\begingroup$ If replace A[0] with constant and solve first for B[k] then solve for A[k] and replace B[k] with previous solution it works. $\endgroup$
    – swish
    Dec 25, 2012 at 13:49
  • 1
    $\begingroup$ Please note that the second one isn't really "coupled" with the first but for a constant term A[0]. So RSolve[B[k]==1+((n-k-2)/n) B[k+1]+((k+1)/n) (k+A[0]),B[k],k] is able to cope with it. $\endgroup$ Dec 25, 2012 at 15:53
  • $\begingroup$ I get a horrible expression from RSolve[B[k]==1+((n-k-2)/n) B[k+1]+((k+1)/n) (k+A[0]),B[k],k] in terms of Gamma, DifferenceRoot, some Function and Pochhammer. Is there some way to extract the leading terms? $\endgroup$
    – Simd
    Dec 25, 2012 at 20:54
  • 1
    $\begingroup$ @lip1 If by "extract the leading terms" you mean generate the first few terms in the sequence, RecurrenceTable is what you are looking for. Unless you can set the value of n though, you get very long expressions. $\endgroup$
    – 0xFE
    Dec 26, 2012 at 3:44
  • $\begingroup$ @belisarius I updated the question to fix some problems and clarify the ranges we are interested in. $\endgroup$
    – Simd
    Dec 27, 2012 at 17:36

1 Answer 1


There may be a better way, but this solves it the same way you did. It generates all the equations and then solves them. If you only want $A_0$, use Sol[n][[1,1]].

Sol[n_] := 
Flatten[Table[{Subscript[B, k] == 
   1 + ((n - k - 1) Subscript[B, k + 1])/n + (k Subscript[A, 0])/
    n, Subscript[A, k] == 
   1 + ((n - k - 2) Subscript[A, k + 1])/n + (
    2 Subscript[B, k + 1])/n + (k Subscript[A, 0])/n}, {k, 0, 
  n - 1}]], {2, -2}]]


Here's a graph of the first 80 values:

Graph of A_0

And the first set of differences:

Differences between consecutive A_0s

That looks somewhere between $\sqrt{x}$ and $\log{x}$.

  • $\begingroup$ Thanks. What I am looking for is a solution as a function of $n$. I just gave an example to make sure it was clear what was going on. I was hoping Rsolve might be able to do something useful. $\endgroup$
    – Simd
    Dec 27, 2012 at 22:27
  • $\begingroup$ @lip1 This is a function of n in the Mathematica sense. Do you mean a mathematical function, like a closed form expression? $\endgroup$
    – 0xFE
    Dec 28, 2012 at 0:21
  • $\begingroup$ Yes that is what I am looking for. $\endgroup$
    – Simd
    Dec 28, 2012 at 7:21
  • $\begingroup$ I've tried fitting some models to it and I have gotten very close, but I haven't found a closed form function. $\endgroup$
    – 0xFE
    Dec 28, 2012 at 18:21
  • $\begingroup$ user141063 Thanks! Shouldn't Rsolve be able to solve it explicitly? $\endgroup$
    – Simd
    Dec 28, 2012 at 21:13

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.