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.

Assume we have a multi-dimensional recurrence, e.g.

$\qquad\begin{align*} a_1 &= (1,2) \\ a_n &= (1,2) + a_{n-1} \quad, n>1 \end{align*}$

with the easy solution $a_n = (n,2n)$.

How can I solve such recurrences in Mathematica? The expression

RSolve[{a[1] == {1, 2}, a[n] == {1, 2} + a[n - 1]}, a[n], n]

evaluates to

{}

in Mathematica 9.0.0.0. Naturally,

RSolve[{
  a1[1] == 1, a1[n] == 1 + a1[n - 1], 
  a2[1] == 2, a2[n] == 2 + a2[n - 1]
}, {a1[n], a2[n]}, n]

works, but this strikes me as inconvenient. Given that the translation is this immediate (provided all occurring lists have the same length) I suspect there might be a way to do it without boilerplate.

share|improve this question
    
For this particular example: RSolve[{a[1] == #, a[n] == # + a[n - 1]}, a[n], n] & /@ {1, 2}. –  Pickett Jul 30 '13 at 13:15
    
@Anon Okay, replacing afterwards in the symbolic result, nice. What are the restrictions of this? –  Raphael Jul 30 '13 at 13:25
    
If the relations cannot be solved separately it won't work. This is equivalent to using RSolve two times, one for each index. –  Pickett Jul 30 '13 at 13:49
    
Because the dimensions may have some inter-dependence, I suspect something like With[{rule=a[n_]:>{a[1][n], a[2][n]}},RSolve[Thread/@({a[1] == {1, 2}, a[n] == {1, 2} + a[n - 1]}/.rule),a[n]/.rule, n]] could be used, but unfortunately I don't have Mathematica available right now so I can't test it. –  VF1 Jul 31 '13 at 4:17
    
@VF1 I don't understand your code but I tried it; the result is also {}. –  Raphael Jul 31 '13 at 12:58
show 5 more comments

1 Answer 1

up vote 1 down vote accepted
SetAttributes[split, HoldAll];
split[var_, eqs_, dim_] := 
 Map[Thread, 
   Hold@eqs /. var[n_] :> Through[(var /@ Range[dim])[n]] // 
    ReleaseHold] // Flatten
RSolve[split[a, {a[1] == {1, 2}, a[n] == {1, 2} + a[n - 1]}, 2], 
split[a, a[n], 2], n]
(* {{a[1][n] -> n, a[2][n] -> 2 n}} *)

split should work for Solve-ing vector-valued functions, too.

share|improve this answer
    
So this essentially translates the set of equations, right? Nice. For the record (this may be obvious) this works also if the underlying recurrences are mutually dependent. –  Raphael Aug 2 '13 at 10:25
    
@Raphael Yes. I had to inject into the Hold and then release it because the problem with the code I posted as a comment was that the Plus was distributing the a[n] term before the replacement, resulting in a matrix when I split it. –  VF1 Aug 2 '13 at 16:37
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.