# Replacing variables in an RSolve expression

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?

-
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

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]


gives

Is this anywhere close to what you expect?

-
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