5
$\begingroup$

I am trying to solve a system of recurrence relations as follows.

RSolve[{a[p] == 1 + (2/n) b[p - 1] + ((p - 1)/n) a[p - 1], 
        b[p] == 1 + (p/n) b[p - 1], 
        a[1] == 1 + 2/n, 
        b[0] == 1}, 
     {a[p], b[p]}, p]

Having done this, I would like to set $p=n-1$ and then plot the resulting functions $a[n-1]$ and $b[n-1]$ for $n=1, ..., 1000$.

I am failing at the first hurdle as Mathematica version 8 just returns the RSolve line when I press shift-enter.

Update. Following a request for an example using Maple 16. I do the following.

rsolve({a(1) = 1+2/n, a(p) = 1+(p-1)*a(p-1)/n+2*b(p-1)/n, b(0) = 1, b(p) = 1+p*b(p-1)/n}, {a(p), b(p)});
subs(p = n-1, %);

I then copy the result for a(n-1) and plot it

plot([seq([n, (1/n)^(n-1)*n*GAMMA(n-1)*(Sum((n+2*(1/n)^p1*exp(n)*GAMMA(p1+1, n))/(n^2*(1/n)^(p1+1)*GAMMA(p1+1)), p1 = 1 .. n-2)+1+2/n)], n = 2 .. 200)], style = point);

This gives

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ First issue is the syntax : RSolve with capital S. $\endgroup$ Commented Jan 1, 2013 at 19:30
  • $\begingroup$ Strongly related mathematica.stackexchange.com/q/16919/193 $\endgroup$ Commented Jan 1, 2013 at 19:41
  • $\begingroup$ Sorry... copy and paste error. I have the same problem with RSolve with a capital S. Is there a way to restart so that there are no existing function/variable settings or is there some other reason it doesn't appear to do anything? $\endgroup$
    – Simd
    Commented Jan 1, 2013 at 19:48
  • 1
    $\begingroup$ solving for b[p] seperately produces a solution for b : solb = RSolve[{b[p] == 1 + (p/n)*b[p - 1], b[0] == 1}, b, p][[1, 1]]. Substituting this in the other equation seems to be more complicated though sola = RSolve[{a[p] == 1 + (2/n)*b[p - 1] + ((p - 1)/n)*a[p - 1], a[1] == 1 + 2/n} /. solb, a, p] $\endgroup$ Commented Jan 1, 2013 at 19:53

1 Answer 1

5
$\begingroup$

In two steps, since they can be decoupled:

h1 = RSolve[{
   b[p] == 1 + (p/n) b[p - 1],
   b[0] == 1}, {b[p]}, p]
h2 = RSolve[{
   a[p] == Evaluate[b[p] /. h1[[1]]] + ((p - 1)/n) a[p - 1],
   a[1] == 1 + 2/n}, {a[p]}, p]

DiscretePlot[{b[i] /. Evaluate[h1 /. p -> n - 1 /. n -> i + 1], Sqrt[i]}, {i, 300}]
DiscretePlot[ a[i] /. Evaluate[h2 /. p -> n - 1 /. n -> i + 1], {i, 300}]

Comparing b[i]with Sqrt[i]

Mathematica graphics

And this is a[i]

Mathematica graphics

Edit

BTW, answering your comment

Thanks. How can I now do the substitution and plotting? If there isn't a bug then it should look like $sqrt(n)$

here is a reasonable approximation to b[i] using Sqrt[]:

y[i_] := Sqrt@(1.78081659706051 + 1.57076044099885*i) - 0.332147990949542; 
DiscretePlot[Evaluate[b[p] /. h1[[1]] /. p -> n - 1 /. n -> i + 1] - y[i], {i,10000}, 
             PlotRange -> All]

Mathematica graphics

Or, if you want an exact result:

b[n] -> E^n n ExpIntegralE[1 - n, n]
$\endgroup$
15
  • $\begingroup$ Thanks. How can I now do the substitution and plotting? If there isn't a bug then it should look like $\sqrt{n}$. $\endgroup$
    – Simd
    Commented Jan 1, 2013 at 19:56
  • $\begingroup$ Thanks but isn't it possible to use the answer to RSolve[{ a[p] == Evaluate[b[p] /. h[[1]]] + ((p - 1)/n) a[p - 1], a[1] == 1 + 2/n}, {a[p]}, p] without having to retype the answer for a[n]? $\endgroup$
    – Simd
    Commented Jan 1, 2013 at 20:04
  • $\begingroup$ @lip1 Look at it now $\endgroup$ Commented Jan 1, 2013 at 20:13
  • $\begingroup$ @belisarius Don't you think Mathematica should be able to solve it the way you did ? $\endgroup$ Commented Jan 2, 2013 at 7:59
  • 1
    $\begingroup$ @lip1 No, you haven't got downvoted. I removed my upvote until you put some more work on your question. You have now two expressions that pretend to solve your problem. I suggest replacing that expressions back into the original equations and see if both of them comply. $\endgroup$ Commented Jan 3, 2013 at 14:23

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.