I simulate a simple experiment, a coin flip. What I do is accumulate the mean of the results up to the i-th experiment. What I can't figure out is why the computed means do not asymptotically approach 1/2. What did I do wrong? The code:

1 Answer
1

It should converge to 1/2, I think you just need to try higher values for n. Which is probably slow with your current non-functional method. Here's a simpler (and faster, and more functional) way to do the same calculation:

@Misery: That's like saying a race car is slow because I don't like switching gears. I use MMA for image processing/number crunching, and in my experience, it is a bit slower but far more productive than e.g. C. If you use it right.
–
nikieJan 19 '13 at 14:29

6

@Misery: No, Mathematica does not "support only functional programming." It supports procedural programming, functional programming, pattern-matching/rule-replacement programming, array-based programming, etc. But as with any interpreted language, the more that can be left to the system to do the better; which is why functional programming can so often be more efficient than procedural programming. Once you "speak" functional programming, you'll like it: it's often much easier to read than procedural programming. Cure the mind-rot of earlier exposure to procedural programming.
–
murrayJan 19 '13 at 15:25

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.