Techniques for Minimization over Integers - wolfram-mathematica

I have to minimize a bunch of functions of n variables that can take values from an integer range.
The functions have the general form:
f[{s1_,... sn_}]:= Kxy KroneckerDelta[sx,sy] + Kwz KroneckerDelta[sw,sz] +/- ..
Where the Kmn are also integers.
As an example,
f[{s1_, s2_, s3_, s4_, s5_}:= KroneckerDelta[s1, s2] - KroneckerDelta[s1, s4] +
KroneckerDelta[s1, s5] + KroneckerDelta[s3, s4] +
KroneckerDelta[s3, s5] + KroneckerDelta[s4, s5];
Where the si_ must be in Range[3].
I can bruteforce easily, for example:
rulez = Table[s[i] -> #[[i]], {i, 5}] & /# Tuples[Range[3], 5];
k1 = f[Table[s[i], {i, 5}]] /. rulez;
{Min[k1], Tuples[Range[3], 5][[#]] & /# Position[k1, Min[k1]]}
(*
->
{-1,{{{1, 2, 2, 1, 3}}, {{1, 2, 3, 1, 2}}, {{1, 3, 2, 1, 3}}, {{1, 3, 3, 1, 2}},
{{2, 1, 1, 2, 3}}, {{2, 1, 3, 2, 1}}, {{2, 3, 1, 2, 3}}, {{2, 3, 3, 2, 1}},
{{3, 1, 1, 3, 2}}, {{3, 1, 2, 3, 1}}, {{3, 2, 1, 3, 2}}, {{3, 2, 2, 3, 1}}}}
*)
Obviously, that seems to take forever for large sets of variables and larger value ranges.
I tried Minimize[ ], but get results that don't satisfy the conditions (!):
Minimize[{f[Table[s[i], {i, 5}]], And ## Table[1 <= s[i] <= 3, {i, 5}]},
Table[s[i], {i, 5}], Integers]
(*
-> {2, {s[1] -> 0, s[2] -> 0, s[3] -> 0, s[4] -> 0, s[5] -> 0}}
*)
Or in other cases, it just fails:
g[{s1_, s2_, s3_, s4_, s5_}]:= KroneckerDelta[s1, s3] - KroneckerDelta[s1, s4] +
KroneckerDelta[s1, s5] + KroneckerDelta[s3, s4] +
KroneckerDelta[s3, s5] + KroneckerDelta[s4, s5];
Minimize[{g[Table[s[i], {i, 5}]], And ## Table[1 <= s[i] <= 3, {i, 5}]},
Table[s[i], {i, 5}], Integers]
(*
->
During evaluation of In[168]:= Minimize::infeas: There are no values of
{s[1],s[2],s[3],s[4],s[5]} for which the constraints 1<=s[1]<=3&&1<=s[2]<=3&&
1<=s[3]<=3&&1<=s[4]<=3&&1<=s[5]<=3 are satisfied and the objective function
KroneckerDelta[s[1],s[3]]-KroneckerDelta[s[1],s[4]]+KroneckerDelta[s[1],s[5]]+
KroneckerDelta[s[3],s[4]]+KroneckerDelta[s[3],s[5]]+KroneckerDelta[s[4],s[5]]
is real valued. >>
Out[169]= {\[Infinity], s[1]->Indeterminate, s[2]->Indeterminate,
s[3]->Indeterminate, s[4]->Indeterminate,
s[5]->Indeterminate}}
*)
So the question is twofold:
Why does Minimize[ ] fail?, and What is the better way to tackle this kind of problems with mathematica?
Edit
Just to emphasize, the first question is:
Why does Minimize[ ] fail?
Not that the other part is less important, but I am trying to learn when to invest my time in lurking with Minimize[ ], and when I shouldn't.

The problem seems to be related to the KroneckerDelta. If I define a function that is equivalent as long as integers are input it works (or at least it looks like it):
In[177]:= kd[x_, y_] := Round[10^-(x - y)^2]
In[179]:=
g[{s1_, s2_, s3_, s4_, s5_}] :=
kd[s1, s3] - kd[s1, s4] + kd[s1, s5] + kd[s3, s4] + kd[s3, s5] +
kd[s4, s5];
Minimize[{g[{s1, s2, s3, s4, s5}],
And ## Map[1 <= # <= 3 &, {s1, s2, s3, s4, s5}]}, {s1, s2, s3, s4,
s5}, Integers]
Out[180]= {-1, {s1 -> 1, s2 -> 1, s3 -> 2, s4 -> 1, s5 -> 3}}

You can set it up as an integer linear programming problem, and send it to Minimize in that form. I show one way to do this below. The Kronecker deltas are now just integer variables constrained between 0 and 1, with certain relations that force k[i,j] to be 1 when s[i]==s[j] and zero otherwise (this uses the coefficient signs and the max coefficient value).
I show the full set of constraints below, along with the expression we'll minimize.
highval = 3;
list = {{1, 2}, {1, 4}, {1, 5}, {3, 4}, {3, 5}, {4, 5}};
coeffs = {1, -1, 1, 1, 1, 1};
v1list = Apply[k, list, 1];
expr = coeffs.v1list
v2list = Map[s, Range[5]];
allvars = Flatten[{v1list, v2list}];
c1 = Map[0 <= # <= 1 &, v1list];
c2 = Map[1 <= # <= highval &, v2list];
c3 = Map[# <= 0 &,
Sign[coeffs]*
Map[{highval*(# - 1) - (s[#[[1]]] - s[#[[2]]]),
highval*(# - 1) - (s[#[[2]]] - s[#[[1]]])} &, v1list], {2}];
c4 = Element[allvars, Integers];
constraints = Flatten[{c1, c2, c3}]
k[1, 2] - k[1, 4] + k[1, 5] + k[3, 4] + k[3, 5] + k[4, 5]
{0 <= k[1, 2] <= 1, 0 <= k[1, 4] <= 1, 0 <= k[1, 5] <= 1, 0 <= k[3, 4] <= 1,
0 <= k[3, 5] <= 1, 0 <= k[4, 5] <= 1,
1 <= s[1] <= 3, 1 <= s[2] <= 3, 1 <= s[3] <= 3, 1 <= s[4] <= 3, 1 <= s[5] <= 3,
3*(-1 + k[1, 2]) - s[1] + s[2] <= 0, 3*(-1 + k[1, 2]) + s[1] - s[2] <= 0,
-3*(-1 + k[1, 4]) + s[1] - s[4] <= 0,-3*(-1 + k[1, 4]) - s[1] + s[4] <= 0,
3*(-1 + k[1, 5]) - s[1] + s[5] <= 0, 3*(-1 + k[1, 5]) + s[1] - s[5] <= 0,
3*(-1 + k[3, 4]) - s[3] + s[4] <= 0, 3*(-1 + k[3, 4]) + s[3] - s[4] <= 0,
3*(-1 + k[3, 5]) - s[3] + s[5] <= 0, 3*(-1 + k[3, 5]) + s[3] - s[5] <= 0,
3*(-1 + k[4, 5]) - s[4] + s[5] <= 0, 3*(-1 + k[4, 5]) + s[4] - s[5] <= 0}
Now just call Minimize, specifying Integers as domain.
Minimize[{expr, constraints}, allvars, Integers]
Out[235]= {-1, {k[1, 2] -> 0, k[1, 4] -> 1, k[1, 5] -> 0,
k[3, 4] -> 0, k[3, 5] -> 0, k[4, 5] -> 0,
s[1] -> 2, s[2] -> 2, s[3] -> 2, s[4] -> 2, s[5] -> 2}}
Daniel Lichtblau
Wolfram Research

Related

Mathematica Nested Manipulates Lag

Ok! I'm working towards building a nested manipulate command that will solve n number of damped oscillating masses in series (with fixed endpoints). I have everything pretty much working but I have one problem - when I increase the number of oscillators, my initial conditions lag behind a bit. For example, if I set n to 4, Mathematica says I still only have 2 initial conditions (the starting number - position and velocity for one oscillator). When I then move to 3, I now have 8 (from my 4 oscillators) - which is too many for the state space equations, and it all fails. What is going on?
(Yes, I know that my initial conditions aren't going to be put in correctly yet, I'm just trying to get them to match up first).
coupledSMD[n_, m_, k_, b_, f_, x0_, v0_, tmax_] :=
Module[{aM, bM, cM, dM},
aM = Join[Table[Boole[i == j - n], {i, n}, {j, 2 n}],
Join[
If[n != 1,DiagonalMatrix[-2 k/m Table[1, {n}]] +
k/m DiagonalMatrix[Table[1, {n - 1}], 1] +
k/m DiagonalMatrix[Table[1, {n - 1}], -1],
{{-2 k/m}}],
If[n != 1,DiagonalMatrix[-2 b/m Table[1, {n}]] +
b/m DiagonalMatrix[Table[1, {n - 1}], 1] +
b/m DiagonalMatrix[Table[1, {n - 1}], -1],
{{-2 b/m}}], 2]];
bM = Join[Table[0, {n}, {1}], Table[1/m, {n}, {1}]];
cM = Table[Boole[i == j], {i, n}, {j, 2 n}];
dM = Table[0, {n}, {1}];
OutputResponse[
{StateSpaceModel[{aM, bM, cM, dM}], Flatten[Join[x0, v0]]},
f, {t, 0, tmax}]
]
Manipulate[
With[{
x0s = Table[Subscript[x, i, 0], {i, 1, n}],
v0s = Table[Subscript[v, i, 0], {i, 1, n}],
initialx = Sequence ## Table[{{Subscript[x, i, 0], 0}, -10, 10}, {i, 1, n}],
initialv = Sequence ## Table[{{Subscript[v, i, 0], 0}, -10, 10}, {i, 1, n}]},
Manipulate[
myplot = coupledSMD[n, m, k, b, f, x0s, v0s, tmax];
Plot[myplot, {t, 0, tmax}, PlotRange -> yheight {-1, 1},
PlotLegends -> Table[Subscript[x, i, 0], {i, 1, n}]],
Style["Initial Positions", Bold],
initialx,
Delimiter,
Style["Initial Velocities", Bold],
initialv,
Delimiter,
Style["System conditions", Bold],
{{m, 1, "Mass(kg)"}, 0.1, 10, Appearance -> "Labeled"},
{{k, 1, "Spring Constant(N/m)"}, 0.1, 10, Appearance -> "Labeled"},
{{b, 0, "Damping Coefficient(N.s/m)"}, 0, 1, Appearance -> "Labeled"},
{{f, 0, "Applied Force"}, 0, 10, Appearance -> "Labeled"},
Delimiter,
Style["Plot Ranges", Bold],
{tmax, 10, 100},
{{yheight, 10}, 1, 100},
Delimiter,
ControlPlacement -> Flatten[{Table[Right, {2 n + 2}], Table[Left, {8}]}]
]],
{n, 1, 4, 1}
]
Edit: Updated the code. It works now, but I'm still getting the errors. I'm guessing that it has something to do with a time lag in the updating process? - That some parts are getting updated before others. Again, it seems to be working perfectly, except it throws these errors (the errors seem superfluous to me, as if they are remnants in the code, but not actually causing a problem)
But I don't really know what I'm talking about :)

convert a number to a variable base in mathematica

let n be an integer and A = {2,3,...,10} and I want to do as follows:
divide n to 2, so there is a reminder r2 and a quotient q2.
divide q2 to 3, so there is a reminder r3 and a quotient q3.
we repeat this until the quotient is less than the next number.
write together the last quotient with the previous reminders.
For example n=45
45/2 ....... r_2=1, q_2=22
22/3 ....... r_3=1, q_3=7
7/4 ....... r_4=3, q_4=1
since q4 = 1 is less than the next number i.e. 5, we break.
the result is q4r4r3r2 where it is equal to 1311.
Thank you for your help.
I did this but it does not work
n = 45;
i = 2;
list = {Mod[n, i]};
While[Quotient[n, i] >= i + 1, n == Quotient[n, i]; i++;
AppendTo[list, Mod[n, i]];
If[Quotient[n, i] < i + 1, Break[]]; AppendTo[list, Quotient[n, i]]];
list
Row[Reverse[list]]
which gives
{1, 0, 15, 1, 11, 0, 9, 3, 7, 3}
Row[{3, 7, 3, 9, 0, 11, 1, 15, 0, 1}]
where it is not my desired result.
This is the code:
A = Table[i, {i, 2, 10}]; (* array of numbers *)
n = 45; (* initial value *)
ans = {}; (* future answer which is now empty list *)
For[i = 1, i <= Length[A], i++, (* looping over A *)
If[n < A[[i]], (* exit condition *)
ans = Append[ans, n]; (* appending last n when exit *)
Break[]
];
qr = QuotientRemainder[n, A[[i]]]; (* calculating both quotient and reminder *)
ans = Append[ans, qr[[2]]]; (* adding second member to the answer *)
Print[qr]; (* printing *)
n = qr[[1]]; (* using first member as new n to process *)
];
ans (* printing result in Mathematica manner *)
It gives
{1, 1, 3, 1}
You might use something like this:
f[n_Integer] :=
NestWhileList[
{QuotientRemainder[#[[1, 1]], #[[2]] + 1], #[[2]] + 1} &,
{{n}, 1},
#[[1, 1]] != 0 &
] // Rest
f[45]
{{{22, 1}, 2}, {{7, 1}, 3}, {{1, 3}, 4}, {{0, 1}, 5}}
You can use Part to get whatever bits of the output you desire.
Here's a somewhat more advanced way if you can handle the syntax:
f2[n_Integer] := Reap[f2[{n, 0}, 2]][[2, 1, 2 ;;]] // Reverse
f2[{q_, r_}, i_] := f2[Sow # r; QuotientRemainder[q, i], i + 1]
f2[{0, r_}, i_] := Sow # r
f2[45]
{1, 3, 1, 1}

Why doesn't backsubstituting the result of Solve[] give the expected result?

I have this matrix
a = {{2, -2, -4}, {-2, 5, -2}, {-4, -2, 2}}
I then solved an equation with one missing entry. The equation is of the form
Inverse[p].a.p == q
where p is the 3x3 matrix with the missing entry (x5) and q is a given 3x3 matrix.
Solve[Inverse[( {
{1/Sqrt[5], 4/(3 Sqrt[5]), -2/3},
{-2/Sqrt[5], 2/(3 Sqrt[5]), -2/6},
{0, x5, -2/3}
} )].a.( {
{1/Sqrt[5], 4/(3 Sqrt[5]), -2/3},
{-2/Sqrt[5], 2/(3 Sqrt[5]), -2/6},
{0, x5, -2/3}
} ) == ( {
{6, 0, 0},
{0, 6, 0},
{0, 0, -3}
} )]
Mathematica can solve this easily and I get x5 -> -(Sqrt[5]/3) as the result.
However if I check it, the result ist very weird:
In[2]:= Inverse[( {
{1/Sqrt[5], 4/(3 Sqrt[5]), -2/3},
{-2/Sqrt[5], 2/(3 Sqrt[5]), -2/6},
{0, -Sqrt[5]/3, -2/3}
} )].a.( {
{1/Sqrt[5], 4/(3 Sqrt[5]), -2/3},
{-2/Sqrt[5], 2/(3 Sqrt[5]), -2/6},
{0, -Sqrt[5]/3, -2/3}
} )
Out[2]= {{6/5 - (2 (-(2/Sqrt[5]) - 2 Sqrt[5]))/Sqrt[5],
8/5 + (2 (-(2/Sqrt[5]) - 2 Sqrt[5]))/(3 Sqrt[5]), -(4/Sqrt[5]) +
1/3 (2/Sqrt[5] + 2 Sqrt[5])}, {-((
2 (-(8/(3 Sqrt[5])) + (4 Sqrt[5])/3))/Sqrt[5]) + (
4/(3 Sqrt[5]) + (4 Sqrt[5])/3)/Sqrt[5],
10/3 + (2 (-(8/(3 Sqrt[5])) + (4 Sqrt[5])/3))/(3 Sqrt[5]) + (
4 (4/(3 Sqrt[5]) + (4 Sqrt[5])/3))/(3 Sqrt[5]), (4 Sqrt[5])/3 +
1/3 (8/(3 Sqrt[5]) - (4 Sqrt[5])/3) -
2/3 (4/(3 Sqrt[5]) + (4 Sqrt[5])/3)}, {0, 0, -3}}
the expected result should be
( {
{6, 0, 0},
{0, 6, 0},
{0, 0, -3}
} )
like in the equation. If I calculate this by hand I get this result. What am I missing here?
Just Simplify or Expand the results.
Here is an example:
In[1]:= a = {{2, -2, -4}, {-2, 5, -2}, {-4, -2, 2}}
Out[1]= {{2, -2, -4}, {-2, 5, -2}, {-4, -2, 2}}
In[2]:= p = {{1/Sqrt[5], 4/(3 Sqrt[5]), -(2/3)}, {-(2/Sqrt[5]), 2/(
3 Sqrt[5]), -(2/6)}, {0, x5, -(2/3)}}
Out[2]= {{1/Sqrt[5], 4/(3 Sqrt[5]), -(2/3)}, {-(2/Sqrt[5]), 2/(
3 Sqrt[5]), -(1/3)}, {0, x5, -(2/3)}}
In[3]:= sol =
Solve[Inverse[p].a.p == {{6, 0, 0}, {0, 6, 0}, {0, 0, -3}}]
Out[3]= {{x5 -> -(Sqrt[5]/3)}}
In[4]:= Inverse[p].a.p /. sol[[1]]
Out[4]= <big output removed>
In[5]:= Simplify[%]
Out[5]= {{6, 0, 0}, {0, 6, 0}, {0, 0, -3}}
Expand would work too in place of Simplify. Expressions in terms of roots and fractions can often be written in several ways, and it's not immediately obvious if two expression are equivalent just by looking at them. You have to explicitly ask Mathematica to transform them, for example expr = 13/(2 Sqrt[3]) - 4/3 and Together[expr].
What is quite strange though, is that Solve does not work if you use the standard syntax and give variables explicitly:
In[6]:= Solve[Inverse[p].a.p == {{6, 0, 0}, {0, 6, 0}, {0, 0, -3}}, x5]
Out[6]= {}
In[7]:= Solve[
Inverse[p].a.p == {{6, 0, 0}, {0, 6, 0}, {0, 0, -3}}, x5,
VerifySolutions -> False]
Out[7]= {}
Can anyone explain why? NSolve works as expected.
In[8]:= NSolve[
Inverse[p].a.p == {{6, 0, 0}, {0, 6, 0}, {0, 0, -3}}, x5]
Out[8]= {{x5 -> -0.745356}}
Remove["Global`*"];
a = {{2, -2, -4}, {-2, 5, -2}, {-4, -2, 2}};
p = {{1/Sqrt[5], 4/(3 Sqrt[5]), -2/3}, {-2/Sqrt[5],
2/(3 Sqrt[5]), -2/6}, {0, x, -2/3}};
pInv = Inverse[p];
lhs = pInv.a.p;
q = {6, 6, -3};
eqs = N#Expand#
Map[Total[lhs[[#, All]]] - q[[#]] == 0 &, Range[Length[q]]]
Here are the 3 equations all in x. (3 equations, ONE unknown!)
-6. - 2.66667/(-0.444444 + 0.745356 x) + (4.47214 x)/(-0.444444 + 0.745356 x) ==
0.,
-6. - 2.66667/(-0.444444 + 0.745356 x) + (4.47214 x)/(-0.444444 + 0.745356 x) == 0.,
3. - 0.654283/(-0.444444 + 0.745356 x) -(1.5694 x)/(-0.444444 + 0.745356 x) + (
4.47214 x^2)/(-0.444444 + 0.745356 x) == 0.
first solve numerically
Map[NSolve[eqs[[#]],x]&,Range[3]]
Out[465]= {{{x->0.}},{{x->0.}},{{x->-0.745356}}}
To get Solve to accept x, First do not do Numerical, leave it symbolic:
eqs = Expand# Map[Total[lhs[[#, All]]] - q[[#]] == 0 &, Range[Length[q]]]
which gives
{-6 - 8/(3 (-(4/9) + (Sqrt[5] x)/3)) + (2 Sqrt[5] x)/(-(4/9) + (Sqrt[5] x)/3) ==
0,
-6 - 8/(3 (-(4/9) + (Sqrt[5] x)/3)) + (2 Sqrt[5] x)/(-(4/9) + (Sqrt[5] x)/3) == 0,
3 + 4/(3 (-(4/9) + (Sqrt[5] x)/3)) - (8 Sqrt[5])/(9 (-(4/9) + (Sqrt[5] x)/3))
+ (2 x)/(3 (-(4/9) + (Sqrt[5] x)/3)) - (
Sqrt[5] x)/(-(4/9) + (Sqrt[5] x)/3) + (
2 Sqrt[5] x^2)/(-(4/9) + (Sqrt[5] x)/3) == 0}
Now use Solve, with explicit x in there, now it is ok
Map[Solve[eqs[[#]], x] &, Range[3]]
{{{}}, {{}}, {{x -> -(Sqrt[5]/3)}}}
--Nasser

How to shade a plot in Mathematica

I want to generate a plot like the following
I am not sure how to generate a shading even though I can get the frame done. I'd like to know the general approach to shade certain areas in a plot in Mathematica. Please help. Thank you.
Perhaps you are looking for RegionPlot?
RegionPlot[(-1 + x)^2 + (-1 + y)^2 < 1 &&
x^2 + (-1 + y)^2 < 1 && (-1 + x)^2 + y^2 < 1 && x^2 + y^2 < 1,
{x, 0, 1}, {y, 0, 1}]
Note the use of op_ in the following (only one set of equations for the curves and the intersection!):
t[op_] :=Reduce[op[(x - #[[1]])^2 + (y - #[[2]])^2, 1], y] & /# Tuples[{0, 1}, 2]
tx = Texture[Binarize#RandomImage[NormalDistribution[1, .005], 1000 {1, 1}]];
Show[{
Plot[y /. ToRules /# #, {x, 0, 1}, PlotRange -> {{0, 1}, {0, 1}}] &# t[Equal],
RegionPlot[And ## #, {x, 0, 1}, {y, 0, 1}, PlotStyle -> tx] &# t[Less]},
Frame->True,AspectRatio->1,FrameStyle->Directive[Blue, Thick],FrameTicks->None]
If, for any particular reason, you want the dotted effect in your picture, you can achieve this like so:
pts = RandomReal[{0, 1}, {10000, 2}];
pts = Select[pts,
And ## Table[Norm[# - p] < 1, {p,
{{0, 0}, {1, 0}, {1, 1}, {0, 1}}}] &];
Graphics[{Thick,
Line[{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}],
Circle[{0, 0}, 1, {0, Pi/2}],
Circle[{1, 0}, 1, {Pi/2, Pi}],
Circle[{1, 1}, 1, {Pi, 3 Pi/2}],
Circle[{0, 1}, 1, {3 Pi/2, 2 Pi}],
PointSize[Small], Point[pts]
}]

Why doesn't Mathematica numerically evaluate this RecurrenceTable?

I'm trying to make a RecurrenceTable with conditionals in Mathematica, and the recursive stuff is working right, but it won't evaluate it completely.
In:= RecurrenceTable[{x[n] == If[Mod[n, 2] == 0, x[n - 1], y[n - 1]],
y[n] == If[Mod[n, 2] == 0, R x[n - 1] (1 - x[n - 1]), y[n - 1]],
x[1] == x0, y[1] == 0}, {x, y}, {n, 1, 10}]
Out:= {{0.25, 0.}, {x[1], 3 (1 - x[1]) x[1]}, {y[2], y[2]}, {x[3],
3 (1 - x[3]) x[3]}, {y[4], y[4]}, {x[5], 3 (1 - x[5]) x[5]}, {y[6],
y[6]}, {x[7], 3 (1 - x[7]) x[7]}, {y[8], y[8]}, {x[9],
3 (1 - x[9]) x[9]}}
These are the right results, but I need it to be in numeric form, i.e. {{0.25, 0.}, {0.25, 0.5625} ...
Is there a way to do this? Thanks!
Typically, you should use Piecewise for mathematical functions, and reserve If for programming flow.
You can convert many If statements using PiecewiseExpand:
If[Mod[n, 2] == 0, x[n - 1], y[n - 1]] // PiecewiseExpand
If[Mod[n, 2] == 0, r*x[n - 1] (1 - x[n - 1]), y[n - 1]] // PiecewiseExpand
The final code may look something like this:
r = 3;
x0 = 0.25;
RecurrenceTable[
{x[n] == Piecewise[{{x[n - 1], Mod[n, 2] == 0}}, y[n - 1]],
y[n] == Piecewise[{{r*x[n - 1] (1 - x[n - 1]), Mod[n, 2] == 0}}, y[n - 1]],
x[1] == x0,
y[1] == 0},
{x, y},
{n, 10}
]
{{0.25, 0.}, {0.25, 0.5625}, {0.5625, 0.5625}, {0.5625,
0.738281}, {0.738281, 0.738281}, {0.738281, 0.579666}, {0.579666,
0.579666}, {0.579666, 0.73096}, {0.73096, 0.73096}, {0.73096, 0.589973}}
A couple of related points:
It is best not to use capital letters for your symbol names, as these may conflict with built-in functions.
You may consider Divisible[n, 2] in place of Mod[n, 2] == 0 if you wish.
RecurrenceTable[{
x[n] == Boole[ Mod[n,2] == 0 ] x[n-1] +
Boole[ Mod[n,2] != 0 ] y[n-1],
y[n] == Boole[ Mod[n,2] == 0 ] 3 x[n-1] (1-x[n-1]) +
Boole[ Mod[n,2] != 0 ] y[n-1],
x[1] == .25, y[1] == 0},
{x, y}, {n, 1, 10}]
with edits R = 3 and x0 = .25 gives the output you expect.

Resources