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 recursive expression, which is something like:

$$ a(n,x)=f(x,y,m)\,a(n-1,x)+g(x,y)\,a(n-1,y) $$

where $f(x,y,m)$ and $g(x,y)$ are known. So the second $a$ depends on $y$ rather than $x$. I tried to get it into RSolve with:

RSolve[{a[n] == f[x, y, n]*a[n-1] + g[x, y]*(a[n] /. {x -> y}), a[0]==1}, a[n], n]

but the /.{x ->y} part doesn't seem to change anything. How can I do the replacement?

share|improve this question
use square brackets [..] instead of parantheses (..). – kglr Jun 4 '14 at 1:23
sorry, that I actually did that in Mathematica, it was just a typeset error here. I edited it, thanks. – gaugi Jun 4 '14 at 1:25
you need to change parentheses of f and g also. – Algohi Jun 4 '14 at 1:29
sorry, another typo in my question... it's $f(x,y,n)$. I have g and f given though, they're just very lengthy, so I didn't want to write them out. – gaugi Jun 4 '14 at 1:32
and if I plug it into Mathematica I get the wrong answer, as Mathematica treats the last $a(n,y)$ as $a(n,x)$, so it doesn't take the ./x->y into account. – gaugi Jun 4 '14 at 1:34
up vote 0 down vote accepted

With typos corrected

RSolve[{a[n, x, y] == f[x, y, m]*a[n - 1, x, y] + g[x, y]*(a[n, x, y] /. {x -> y}), 
        a[0, x, y] == 1}, a[n, x, y], n]


enter image description here

Is this anywhere close to what you expect?

share|improve this answer
but I want the $x->y$ only for the second a[n] – gaugi Jun 4 '14 at 2:04
@gaugi, I see... Pls see the update.. – kglr Jun 4 '14 at 2:13
yes, thank you, this is close. Unfortunately there are still a[K[1],y,y] in the answer, though. – gaugi Jun 4 '14 at 2:18

Your Answer


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.