How do I calculate the mean of A for higher values of k

\[Psi] = Sqrt[2] - 1;
\[Epsilon] = .001;
\[Omega] = 1000000;
k = 20;
j = 1;
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]]];

For k=20, I get that the memory of the system has exceeded. I'm not sure what additional code I must use?

  • 1
    $\begingroup$ Are you sure this is the code you're executing? I find that A1 and A2 actually get smaller as k increases. At k = 20 A1 has zero elements. Since it has no intersection with A2, this means that A is also empty and has a length of zero. The error I get when I run your code is a divide by zero error, not a memory error. $\endgroup$
    – MassDefect
    Jun 25 at 19:48
  • $\begingroup$ @MassDefect I assume is a value of k that gives the maximum average because initially from k=10 it seems the average was increasing $\endgroup$
    – Arbuja
    Jun 25 at 20:01
  • $\begingroup$ @MassDefect Yes this the code I want. I wanted be sure that the average of A was decreasing after a certain $k$. $\endgroup$
    – Arbuja
    Jun 25 at 20:11
  • 1
    $\begingroup$ @MassDefect for k=20 his code A2 makes a 2D table with $\omega^{1/j} = 1,000,000$ elements in the outer layer. For each of those elements, it makes a list - most of which are trivial but a few thousand are not. I can see it pushing the limits on an older or smaller machine, no? $\endgroup$
    – bRost03
    Jun 25 at 20:59
  • 1
    $\begingroup$ @Arbuja A is {} for k=20 $\endgroup$
    – bRost03
    Jun 25 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.