I tried computing the following
Unprotect[C]
\[Psi] = Sqrt[2] - 1;
\[Epsilon] = .001;
\[Omega] = 50000;
k = 13;
j = 3;
A1 = Flatten[
Table[(s1^j)/(s2^k), {s2, 1, Floor[\[Omega]^(1/k)]}, {s1,Ceiling[((s2^k) (\[Psi] - \[Epsilon]))^(1/j)],
Floor[((s2^k) (\[Psi] + \[Epsilon]))^(1/j)] }]];
A2 = Flatten[
Table[(s1^j)/(s2^k), {s1, 1, Floor[\[Omega]^(1/j)]}, {s2,
Ceiling[((s1^j)/(\[Psi] + \[Epsilon]))^(1/k)],
Floor[((s1^j)/(\[Psi] - \[Epsilon]))^(1/k)]}]];
A = DeleteDuplicates[Flatten[Intersection[A1, A2]]];
C1 = DeleteDuplicates[
Flatten[Table[(s1^j)/(2 s2 + 1)^k, {s2, 1,
Floor[(10 \[Omega])^(1/k)]}, {s1,
Ceiling[(((2 s2 + 1)^k) (\[Psi] - \[Epsilon]))^(1/j)],
Floor[(((2 s2 + 1)^k) (\[Psi] + \[Epsilon]))^(1/j)]}]]];
C2 = DeleteDuplicates[
Flatten[Table[(s1^j)/(2 s2 + 1)^k, {s1, 1,
Floor[(10 \[Omega])^(1/j)]}, {s2,
Ceiling[(((s1^j)/(\[Psi] + \[Epsilon]))^(1/k) - 1)/2],
Floor[(((s1^j)/(\[Psi] - \[Epsilon]))^(1/k) - 1)/2]}]]];
C = DeleteDuplicates[Flatten[Intersection[C1, C2]]];
g1 = N[Length[Intersection[A, C]]/Length[A]];
When j=1
the code works fine but when j
is an integer greater than 1
, it returns an error sign:
Power::infy: Infinite expression 1/0 encountered.
Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered.
I tried fixing it using DeleteCases
to delete the zeros (see t1
and t2
)
Unprotect[C]
\[Psi] = Sqrt[2] - 1;
\[Epsilon] = .001;
\[Omega] = 50000;
k = 13;
j = 3;
t1 = DeleteCases[
Table[s1, {s1, Ceiling[((s2^k) (\[Psi] - \[Epsilon]))^(1/j)],
Floor[((s2^k) (\[Psi] + \[Epsilon]))^(1/j)]}], 0]
t2 = DeleteCases[
Table[s2, {s2, Ceiling[((s1^j)/(\[Psi] + \[Epsilon]))^(1/k)],
Floor[((s1^j)/(\[Psi] - \[Epsilon]))^(1/k)]}], 0]
A1 = Flatten[
Table[(s1^j)/(s2^k), {s2, 1, Floor[\[Omega]^(1/k)]}, {s1,t1 }]];
A2 = Flatten[
Table[(s1^j)/(s2^k), {s1, 1, Floor[\[Omega]^(1/j)]}, {s2,
t2}]];
A = DeleteDuplicates[Flatten[Intersection[A1, A2]]];
C1 = DeleteDuplicates[
Flatten[Table[(s1^j)/(2 s2 + 1)^k, {s2, 1,
Floor[(10 \[Omega])^(1/k)]}, {s1,
Ceiling[(((2 s2 + 1)^k) (\[Psi] - \[Epsilon]))^(1/j)],
Floor[(((2 s2 + 1)^k) (\[Psi] + \[Epsilon]))^(1/j)]}]]];
C2 = DeleteDuplicates[
Flatten[Table[(s1^j)/(2 s2 + 1)^k, {s1, 1,
Floor[(10 \[Omega])^(1/j)]}, {s2,
Ceiling[(((s1^j)/(\[Psi] + \[Epsilon]))^(1/k) - 1)/2],
Floor[(((s1^j)/(\[Psi] - \[Epsilon]))^(1/k) - 1)/2]}]]];
C = DeleteDuplicates[Flatten[Intersection[C1, C2]]];
g1 = N[Length[Intersection[A, C]]/Length[A]];
However, I continue to get Power::Infty
.
How do we fix my code?
Unprotect[C]
<- This is a very bad idea and it does break stuff. Even if it is not responsible for the specific issue you are asking about, it will prevent some people from evaluating your code and try to help you. $\endgroup$A1
andA2
are empty whenj
is an integer greater than one. I believe this is since the lower bound ofA1
andA2
is greater than the upper bound ofA1
andA2
. $\endgroup$Length[A]==0
? You haveN[Length[Intersection[A, C]]/Length[A]]
so of course you can expect that error whenA
is empty. $\endgroup$