# Solving recurrence relation using Mathematica defined in a piecewise way

I have a recurrence relation defined as following:

RSolve[
{
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:

RSolve[
{
p[i + 1] ==
Piecewise[{
{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.

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

-

## migrated from stackoverflow.comMay 3 '12 at 19:22

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

This works:

RSolve[{
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
*)


Edit

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.

-