# How to solve this recursive system?

I try to solve the equation system as

p[n_] := Piecewise[{{a, Mod[n, 2] == 0}, {b, Mod[n, 2] == 1}}]

q[n_] := Piecewise[{{c,Mod[n,2]==0},{d,Mod[n,2]==1}}]

RSolve[
{x[n + 1] == (p[n] + y[n])/(p[n] + y[n - 2]),
y[n + 1] == (q[n] + x[n])/(q[n] + x[n - 2]), x[-2] == A, x[-1] == B,
x == H, y[-2] == J, y[-1] == M, y == L}, {x[n], y[n]}, n
]


but I didn't achieve this. When I execute the process, RSolve can't solve the system. How can I deal with this? Thank you.

• Not that it helps with your problem but I'd like to point out that you have used a few reserved keywords as variables in your code (E and D). In order to prevent conflicts you better refrain from using variables with an initial uppercase character. – Sjoerd C. de Vries Feb 4 '16 at 19:56
• You're right. I have edited the expressions. Thank you... – drxy Feb 4 '16 at 20:01
• What, precisely, are you seeking? This system of difference equations may not have a closed-form analytical solution, just as many differential equations do not. Nonetheless, they can be solved numerically. – bbgodfrey Feb 4 '16 at 22:29

Just to illustrate @bbgodfrey 's comment. If I have coded recursion correctly (noting NestList and many other refinements I have not done):

p[n_?EvenQ] := a
p[n_] := b
q[n_?EvenQ] := c
q[n_] := d
r[n_, {x__}, {y__}, {pq__}] :=
Nest[{#[], #[], (p[#[]] + #[])/(p[#[]] + #[]),
#[], #[],
(q[#[]] + #[])/(q[#[]] + #[]),
#[] + 1} /. Thread[{a, b, c, d} -> {pq}] &,
{x, y, 0}, n]
rc[n_, {x__}, {y__}, {pq__}] := r[n, {x}, {y}, {pq}][[{3, 6}]]


You can play:

Manipulate[
ListPlot[Transpose@(rc[#, {x1, x2, x3}, {y1, y2, y3}, {m, s, u,
v}] & /@ Range[n]), Joined -> True, PlotRange -> All,
PlotLegends -> {"\!$$\*SubscriptBox[\(x$$, $$n$$]\)",
"\!$$\*SubscriptBox[\(y$$, $$n$$]\)"}],
{n, {10, 20, 30}}, {x1, 1, 10}, {x2, 1, 10}, {x3, 1, 10}, {y1, 1,
10}, {y2, 1, 10}, {y3, 1, 10}, {m, 1, 10}, {s, 1, 10}, {u, 1,
10}, {v, 1, 10}] Apologies for errors or misunderstanding.

• Inspring from your code I have solved my problem. Thank you very much. – drxy Feb 9 '16 at 13:37
• @drxy I am glad it was some help to you in achieving your goal :) – ubpdqn Feb 10 '16 at 4:24