Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

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
add comment

migrated from stackoverflow.com May 3 '12 at 19:22

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

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

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