Reputation: 11
I need some help with my Mathematica homework.. I want to get the mean of some random numbers from 0 to 10 and that each time for a higher amount of samples (from 10 to 20). Then I would like to plot it somehow as a distribution of all means or if that's not possible as a List Plot. I have to show that with a rising amount of samples, the mean becomes more and more correct. That's what I already have..
For[i = 10, i < 20, i++, Print[Mean[RandomInteger[10, i]]]]
I'm grateful for every help!!
Upvotes: 1
Views: 189
Reputation: 8655
For
loops do not return results, so they have to be collected.
Print
won't help.
output = {};
For[i = 10, i < 20000, i++, AppendTo[output, Mean[RandomInteger[10, i]]]]
ListPlot[output, AxesLabel -> {"Samples", "Mean"}]
Better to use Table
instead of For
. Table
does return results.
output = Table[Mean[RandomInteger[10, i]], {i, 10, 20000}];
ListPlot[output, AxesLabel -> {"Samples", "Mean"}]
Upvotes: 1