Talk:Monte Carlo methods: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 2: Line 2:
I noted that someone had changed another Python shell session used as an example, into the 'normal' definition of a function followed by the shell session just used to show the answer when the function is called.<br>
I noted that someone had changed another Python shell session used as an example, into the 'normal' definition of a function followed by the shell session just used to show the answer when the function is called.<br>
I don't think this should be done here, as I am attempting to show how the shell might be used for such a task. It is still Python. The repitition of the input expression is because in idle, the built-in graphical IDE for Python, you would hit return in a previous expression to re-enter it. In the non-graphical shell, you can scroll through previous input to re-enter lines. It can give the immediate feedback, and 'spirit of exploration' you get when working with a calculator. --[[User:Paddy3118|Paddy3118]] 05:22, 2 October 2008 (UTC)
I don't think this should be done here, as I am attempting to show how the shell might be used for such a task. It is still Python. The repitition of the input expression is because in idle, the built-in graphical IDE for Python, you would hit return in a previous expression to re-enter it. In the non-graphical shell, you can scroll through previous input to re-enter lines. It can give the immediate feedback, and 'spirit of exploration' you get when working with a calculator. --[[User:Paddy3118|Paddy3118]] 05:22, 2 October 2008 (UTC)

== Error formula in C implementation ==

What formula is being used for the error calculation in the [http://rosettacode.org/wiki/Monte_Carlo_methods#C C Implementation]?

At first I thought it was the formula for standard deviation but the code is:

error = val * sqrt(val (1 - val) / sampled) * 4;

The factor 4 is explained because we are not interested in the ratio <math>\pi/4</math>, but in <math>\pi</math> so both the value and the error must be multiplied by 4. The rest of the code translates to:



<math>\sigma = \mu \sqrt{\frac{1}{N} \mu(1 - \mu)}, {\rm \ \ where\ \ } \mu {\rm \ \ is \ \ the \ \ ratio \ \ } \pi/4 {\rm \ \ and\ \ } N {\rm \ \ is \ \ the \ \ number \ \ of \ \ samples \ \ }</math>


But according to [http://en.wikipedia.org/wiki/Standard_deviation#Definition_of_population_values Wikipedia] the formula is this:
:<math>\sigma = \sqrt{\frac{1}{N} \sum_{i=1}^N (x_i - \mu)^2}, {\rm \ \ where\ \ } \mu = \frac{1}{N} \sum_{i=1}^N x_i.</math>


Can somebody explain this more clearly? I'm not yet convinced this is correct

Revision as of 01:02, 5 May 2014

Python shell sessions as examples

I noted that someone had changed another Python shell session used as an example, into the 'normal' definition of a function followed by the shell session just used to show the answer when the function is called.
I don't think this should be done here, as I am attempting to show how the shell might be used for such a task. It is still Python. The repitition of the input expression is because in idle, the built-in graphical IDE for Python, you would hit return in a previous expression to re-enter it. In the non-graphical shell, you can scroll through previous input to re-enter lines. It can give the immediate feedback, and 'spirit of exploration' you get when working with a calculator. --Paddy3118 05:22, 2 October 2008 (UTC)

Error formula in C implementation

What formula is being used for the error calculation in the C Implementation?

At first I thought it was the formula for standard deviation but the code is:

error = val * sqrt(val (1 - val) / sampled) * 4;

The factor 4 is explained because we are not interested in the ratio , but in so both the value and the error must be multiplied by 4. The rest of the code translates to:



But according to Wikipedia the formula is this:


Can somebody explain this more clearly? I'm not yet convinced this is correct