Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a recurrence relation defined as following:

  p[0] == p0,
  p[1] == λ p[0]/μ,
  p[i + 1] == λ p[i]/(2 μ)
 p[i], i

Note that the relation is differently for i=1, than for i >= 1. This yields the following error:

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

When I use Piecewise, Mathematica just echos the input:

  p[i + 1] == 
     {p0, i == -1},
     {λ p[i]/μ, i == 0}, 
     {λ p[i]/(2 μ), i >= 1}}]
 p[i], i

Also using If or Condition does not to work out.

Appreciate your help!

(Btw, this simple example can easily be solved by hand, but I would like to solve more complicated recursions involving piecewise definitions.)

share|improve this question

migrated from May 3 '12 at 19:22

This question came from our site for professional and enthusiast programmers.

This works:

  p[1] == l p0/m,
  p[n + 1] == l /(2 m) p[n]},
  p[n], n]
  -> {{p[n] -> 2^(1 - n) (l/m)^n p0}}

(The overspecification of p[0] and p[1] is not to the taste of RSolve)

Another way:

k[0] = k0;
k[1] = l k[0]/m;
k[i_] := l k[i - 1]/(2 m) /; i > 1;
FindSequenceFunction[Table[k[i], {i, 1, 10}], n]
-> 2^(1 - n) k0 (l/m)^n


Reader, beware! As of v8.0, RSolve and FindSequenceFunction are both immature implementations (I think), and there a lot of cases where the output is just the input.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.