I am very interested in mathematics, suffering from the mathematical theorem formula to be afraid of life, have always wanted to use a simple, popular way to show the charm of mathematics, Learning R language for a period of time, feel can use this tool to verify some mathematical theorem, also is a kind of fun, say dry, first a simple point
Large number theorem:
In the large number of repeated occurrences of random events, it tends to show almost inevitable law, which is the law of large numbers. In layman's terms, the theorem is that, under the condition of constant experimentation, repeated experiments have several times, and the frequency of random events approximates its probability. For example, we throw a coin upwards, which side of the coin falls on it is accidental, but when we have enough to toss a coin, tens of thousands of times or even hundreds of thousands of millions of times, we will find that the number of coins each face up to about one-second of the total number of times, accidental inclusion of some inevitable.
Verification Code:
Big_num<-function (n=1000)
{
count<-0
For (i in 1:n)
{
if (sample (C (0,1), 1) ==1) count<-count+1 # #随机从0, 1 sample, Count equals 1
}
Return (count/n) # #返回1出现的频率
}
Operation Result:
> Big_num ()
[1] 0.49
> Big_num (10000)
[1] 0.5027
> Big_num (100000)
[1] 0.49872
> Big_num (1000000)
[1] 0.499487
> Big_num (10000000)
[1] 0.4997597
>
Sure enough, as the number of experiments increases, the frequency of 1 appears to be approximately the probability of each experiment (0.5)
Verifying large number theorems with R language