pi的R语言模拟
require(plotrix)
require(grid)
simp <- function(n){
x <- runif(n)
y <- runif(n)
xy <- x^2 + y^2
ind <- xy <=1
up <- length(xy[which(xy <= 1)])
pai <- up /n * 4
plot(c(0, 1), c(0, 1), type = 'n', asp = 1,
main = bquote(pi == .(pai)), xlab="",ylab="")
rect(0, 0, 1, 1)
draw.circle(0, 0, 1)
points(x, y, pch = 20, cex = .5,
col = ind+1)
}
simp(50000)
require(grid)
simp <- function(n){
x <- runif(n)
y <- runif(n)
xy <- x^2 + y^2
ind <- xy <=1
up <- length(xy[which(xy <= 1)])
pai <- up /n * 4
plot(c(0, 1), c(0, 1), type = 'n', asp = 1,
main = bquote(pi == .(pai)), xlab="",ylab="")
rect(0, 0, 1, 1)
draw.circle(0, 0, 1)
points(x, y, pch = 20, cex = .5,
col = ind+1)
}
simp(50000)
热门话题 · · · · · · ( 去话题广场 )
- 维系精神生活的北京角落 960次浏览
- 我在网络上感受到的陌生人善意 458次浏览
- 少年时代的科普读物 新话题
- 身边的科普现场 新话题
- 现代人的“卡夫卡时刻” 2085次浏览
- 一人一杯一口入魂的夏日特饮 1.2万次浏览