Skip to content

Instantly share code, notes, and snippets.

@klauszhang
Last active June 16, 2016 05:16
Show Gist options
  • Save klauszhang/77ec184fba3748b948e9c53949724493 to your computer and use it in GitHub Desktop.
Save klauszhang/77ec184fba3748b948e9c53949724493 to your computer and use it in GitHub Desktop.
size<-1000
devider<-10
Nt<-numeric(size)
result<-numeric(size/devider)
for (i in 1:size) {
X<-runif(1000, min=0, max=1)
S<-cumsum(X)
t<-100
Nt[i]<-sum(S<t)
result[i]<-sum(Nt)/i
}
mean(Nt)
exp(.5)-1
plot(y=result, x=1:size/devider,pch=16,cex=0.1)
abline(h=exp(t)-1, col='red',lwd=2)
hist(Nt, probability = T)
somevalue<-seq(from=150,to=250,by=.1)
sd<-sqrt(t*1/(12*.5^3))
lines(x=somevalue,y = dnorm(somevalue, mean=t/.5, sd = sd))
#plot(table(Nt))
exp<-rnorm(100000, mean=0, sd=1)
hist(exp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment