I am interested in "automating" the following notebook file so that I can execute it many times to generate many plots.

roots = x /. NSolve[Sum[RandomVariate[NormalDistribution[]]*x^k, {k, 0, 1000}] ==
 0, x, Reals]
difs = Differences[roots]
a = Tally[difs]
ListPlot[a, AxesLabel -> {diffs, occurences}, PlotLabel -> "A Degree 1000" , PlotRange -> Full]
Export["plot.pdf", %]

Each time the code is evaluated, I of course obtain a different plot. I would like to have maybe 100 of the plots but this would be rather tedious as I have to save the plot output as a PDF individually and run the whole notebook each time. I also want to do other degrees than 1000 so I will definitely need to automate this process. I have looked into the Wolfram Script stuff, but am a bit lost/ not sure what to do. Is it possible to turn this notebook file (with 4 cells of evaluation) into a script such that I can just run it over and over with one easy command in a command line to generate multiple plots?

Any help with this issue is immensely appreciated! Thank you!

  • $\begingroup$ Add another line to export plot as PDF and wrap the whole process in a Do loop? $\endgroup$ – Pinti Jun 26 '17 at 18:44
  • $\begingroup$ @Pinti this just results in tons of errors though $\endgroup$ – David_Shmij Jun 26 '17 at 18:57
  • $\begingroup$ I do not think you need to use Wolfram Script. You can just use Table to Map. Also, please post code, not images with code. $\endgroup$ – Anton Antonov Jun 26 '17 at 19:19
  • $\begingroup$ @AntonAntonov Sorry about that , I put the code now. What do you mean by use Table to Map? Thank you for your comment! $\endgroup$ – David_Shmij Jun 26 '17 at 19:30

This generates and exports 10 images with your code:

 roots = 
  x /. NSolve[
    Sum[RandomVariate[NormalDistribution[]]*x^k, {k, 0, 1000}] == 0, 
    x, Reals];
 difs = Differences[roots];
 a = Tally[difs]; 
 Export["/some/path/plot" <> ToString[i] <> ".pdf", 
  ListPlot[a, AxesLabel -> {diffs, occurences}, 
   PlotLabel -> "A Degree 1000", PlotRange -> Full]]
 , {i, 10}]

Your Answer

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

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