# Help Solving A Recusive System: “\$RecursionLimit::reclim: Recursion depth of 256 exceeded.”

Was wondering if anyone had any tricks/ideas on solving this system of recursive equations I have. Essentially my goal is to have J2 equal to zero, but to understand how tweaking several parameters affects the J2 value.

Here is the code:

Subscript[
x, β1] = -Subscript[η, 1] Subscript[δ, 1] +
Sqrt[2 Subscript[J, 1] Subscript[β, 1]] Cos[Subscript[μ,
1]];

Subscript[
x, β1PRIME] = -Subscript[η, 1 PRIME] Subscript[δ,
1] - Sqrt[(2 Subscript[J, 1])/Subscript[β,
1]] (Subscript[α, 1] Cos[Subscript[μ, 1]] +
Sin[Subscript[μ, 1]]);

Subscript[J, 1] =
1/2 (((1 + Subscript[α, 1]^2)/Subscript[β,
1]) Subscript[x, β1]^2 +
2 Subscript[α, 1] Subscript[x, β1] Subscript[
x, β1PRIME] +
Subscript[β, 1] Subscript[x, β1PRIME]^2);

Subscript[
x, β2] = -Subscript[η, 2] Subscript[δ, 2] +
Sqrt[2 Subscript[J, 1] Subscript[β, 2]] Cos[Subscript[μ,
2]];

Subscript[
x, β2PRIME] = -Subscript[η, 2 PRIME] Subscript[δ,
2] - Sqrt[(2 Subscript[J, 1])/Subscript[β,
2]] (Subscript[α, 2] Cos[Subscript[μ, 2]] +
Sin[Subscript[μ, 2]]);

Subscript[J, 2] =
1/2 (((1 + Subscript[α, 2]^2)/Subscript[β,
2]) Subscript[x, β2]^2 +
2 Subscript[α, 2] Subscript[x, β2] Subscript[
x, β2PRIME] +
Subscript[β, 2] Subscript[x, β2PRIME]^2);


These are not equations, they are assignments (or definitions) and you are defining Subscript[x, β2] in terms of Subscript[J, 2] while simultaneously defining Subscript[J, 2] in terms of Subscript[x, β2]. This causes infinite recursion.

Notice that everything depends on J1. Can we find J1?

result1 = (J1 == 1/2 (((1 + α1^2)/β1) xβ1^2 + 2 α1*
xβ1 xβ1PRIME + β1 xβ1PRIME^2)) //.
{xβ1 -> -η1 δ1 + Sqrt[2 J1 β1] Cos[μ1],
xβ2 -> -η2 δ2 + Sqrt[2 J1 β2] Cos[μ2],
xβ1PRIME -> -η1PRIME δ1 - Sqrt[(2 J1)/β1] (α1*
Cos[μ1] + Sin[μ1]),
xβ2PRIME -> -η2PRIME δ2 - Sqrt[(2 J1)/β2] (α2*
Cos[μ2] + Sin[μ2])}


which gives us

J1 == 1/2 (((1 + α1^2) (-δ1 η1 + Sqrt[2] Sqrt[J1 β1]*
Cos[μ1])^2)/β1 + 2 α1 (-δ1 η1 + Sqrt[2] Sqrt[J1*
β1] Cos[μ1]) (-δ1 η1PRIME - Sqrt[2] Sqrt[J1/β1]*
(α1 Cos[μ1] + Sin[μ1])) + β1 (-δ1 η1PRIME -
Sqrt[2] Sqrt[J1/β1] (α1 Cos[μ1] + Sin[μ1]))^2)


Simplify assuming β1 > 0

result2 = Simplify[result1, β1 > 0]


which gives us, all in terms of Sqrt[J1]

δ1 (δ1 ((1 + α1^2) η1^2 + 2 α1 β1*
η1 η1PRIME + β1^2 η1PRIME^2) - 2 Sqrt[2] Sqrt[J1*
β1] η1 Cos[μ1] + 2 Sqrt[2] (α1 Sqrt[J1 β1]*
η1 + Sqrt[J1] β1^(3/2) η1PRIME) Sin[μ1]) == 0


Solve that for Sqrt[J1] with concerns about signs which gives us

Sqrt[J1] == (δ1 (η1^2 + α1^2 η1^2 + 2 α1*
β1 η1 η1PRIME + β1^2 η1PRIME^2))/(2 Sqrt[2]*
Sqrt[β1] (η1 Cos[μ1] - α1 η1 Sin[μ1] -
β1 η1PRIME Sin[μ1]))


Attack J2

result3 = (J2 == 1/2 (((1 + α2^2)/β2) xβ2^2 + 2 α2*
xβ2 xβ2PRIME + β2 xβ2PRIME^2)) //.
{xβ1 -> -η1 δ1 + Sqrt[2 J1 β1] Cos[μ1],
xβ2 -> -η2 δ2 + Sqrt[2 J1 β2] Cos[μ2],
xβ1PRIME -> -η1PRIME δ1 - Sqrt[(2 J1)/β1] (α1*
Cos[μ1] + Sin[μ1]),
xβ2PRIME -> -η2PRIME δ2 - Sqrt[(2 J1)/β2] (α2*
Cos[μ2] + Sin[μ2])}


which gives us

J2 == 1/2 (((1 + α2^2) (-δ2 η2 + Sqrt[2] Sqrt[J1 β2]*
Cos[μ2])^2)/β2 + 2 α2 (-δ2 η2 + Sqrt[2] Sqrt[J1*
β2] Cos[μ2]) (-δ2 η2PRIME - Sqrt[2] Sqrt[J1/β2]*
(α2 Cos[μ2] + Sin[μ2])) + β2 (-δ2 η2PRIME -
Sqrt[2] Sqrt[J1/β2] (α2 Cos[μ2] + Sin[μ2]))^2)


Simplify assuming β2 > 0

result4 = Simplify[result3, β2 > 0]


which gives us

2 J1 β2 + δ2^2 ((1 + α2^2) η2^2 + 2 α2 β2*
η2 η2PRIME + β2^2 η2PRIME^2) + 2 Sqrt[2] δ2*
(α2 Sqrt[J1 β2] η2 + Sqrt[J1] β2^(3/2) η2PRIME)*
Sin[μ2] == 2 (J2 β2 + Sqrt[2] Sqrt[J1 β2] δ2 η2*
Cos[μ2])


Manual rearrangement of Sqrt with concerns about signs gives us

(2 (Sqrt[J1])^2 β2 + δ2^2 ((1 + α2^2) η2^2 + 2 α2*
β2 η2 η2PRIME + β2^2 η2PRIME^2) + 2 Sqrt[2] δ2*
(α2 Sqrt[J1] Sqrt[β2] η2 + Sqrt[J1] β2^(3/2)*
η2PRIME) Sin[μ2] == 2 (J2 β2 + Sqrt[2] Sqrt[J1] Sqrt[β2]*
δ2 η2 Cos[μ2]))


Substitute for Sqrt[J1] gives us

(2 ((δ1 (η1^2 + α1^2 η1^2 + 2 α1 β1 η1*
η1PRIME + β1^2 η1PRIME^2))/(2 Sqrt[2] Sqrt[β1] (η1*
Cos[μ1] - α1 η1 Sin[μ1] - β1 η1PRIME*
Sin[μ1])))^2 β2 + δ2^2 ((1 + α2^2) η2^2 +
2 α2 β2 η2 η2PRIME + β2^2 η2PRIME^2) +
2 Sqrt[2] δ2 (α2 ((δ1 (η1^2 + α1^2 η1^2 +
2 α1 β1 η1 η1PRIME + β1^2 η1PRIME^2))/(
2 Sqrt[2]Sqrt[β1] (η1 Cos[μ1] - α1 η1 Sin[μ1] -
β1 η1PRIME Sin[μ1]))) Sqrt[β2] η2 + ((δ1*
(η1^2 + α1^2 η1^2 + 2 α1 β1 η1 η1PRIME +
β1^2 η1PRIME^2))/(2 Sqrt[2]Sqrt[β1] (η1 Cos[μ1] -
α1 η1 Sin[μ1] - β1 η1PRIME Sin[μ1]))) β2^(
3/2) η2PRIME) Sin[μ2] == 2 (J2 β2 + Sqrt[2] ((δ1*
(η1^2 + α1^2 η1^2 + 2 α1 β1 η1 η1PRIME +
β1^2 η1PRIME^2))/(2 Sqrt[2] Sqrt[β1] (η1 Cos[μ1] -
α1 η1 Sin[μ1] - β1 η1PRIME Sin[μ1])))*
Sqrt[β2] δ2 η2 Cos[μ2]))


Now that looks complicated, but it has eliminated all of your intermediate functions and the result is J2 strictly in terms of your coefficients. In addition there are two large common denominators in that, making it look much bigger than it really is. There is only a single instance of your J2 in that. With careful checking you can solve that for J2 and might even be able to see what effect your coefficients have on J2.

Check all this carefully before you depend on it.

If I have made any mistakes or misunderstood what you were asking for then please explain this clearly and I will see what I can do to correct this.