0
$\begingroup$

so I have a program that outputs a desired value for incrementing values of alpha. Right now, my program prints a list of these for 40 values of alpha in the form {alpha, newValue}.

d = 1000;
For[k = 1, k <= 40, k++,
  alpha = 0.1*k;
  fd = 3*d^2/(Pi^2);
   fs = fd*FareySequence[d];
  count = 0; 
  For[i = 1, i < fd, i++, 
   For[j = (i - 1), j > 0, j--, 
     If[(fs[[i]] - fs[[j]]) < alpha, count++, Break[]]];];
    newValue = count/d^2;
  Print["{", alpha, ",", newValue, "}"];
  ];

Here are the first few outputs:

{0.1,0}
{0.2,0}
{0.3,0}
{0.4,1911/100000}
{0.5,13593/250000}
{0.6,90521/1000000}
..
..
..
{3.9,1155653/1000000}
{4.,74163/62500}

I want to make a plot all of these outputs as coordinates. I want to plot these point on a graph with alpha on the x axis and newValue on the y axis. Any help would be appreciated.

$\endgroup$

1 Answer 1

2
$\begingroup$

Change the outer for loop to a table:

d = 1000;
sol = Table[alpha = 0.1*k;
fd = 3*d^2/(Pi^2);
fs = fd*FareySequence[d];
count = 0;
For[i = 1, i < fd, i++, 
For[j = (i - 1), j > 0, j--, 
If[(fs[[i]] - fs[[j]]) < alpha, count++, Break[]]];];
{k, count/d^2}, {k, 1, 40}];

ListPlot[sol]

gives the plot you're looking for!

enter image description here

$\endgroup$
3
  • $\begingroup$ I'm getting an error "sol is not a list of numbers or pairs of numbers." $\endgroup$ Commented Oct 17, 2020 at 15:08
  • $\begingroup$ @ NotSoTrivial I checked my code , it runs without error. Perhaps restart your session and try again ! $\endgroup$ Commented Oct 17, 2020 at 15:12
  • $\begingroup$ Yes, thanks it works. The run time was just too long for large d. I also changed some of the parameters to make it a function of alpha. Thanks a lot! $\endgroup$ Commented Oct 17, 2020 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.