# Compute area of quarter circle # using random point simulation techniques # create n random (x,y) points in square of dimension dim1 n <- 200 ; dim1 <- 750 x <- sample(0:dim1,size=n, replace=TRUE) y <- sample(0:dim1,size=n, replace=TRUE) x ; y # create points (xi,y) on circle perimeter yfunction <- c() for (i in 1:n) { yfunction[i] <- sqrt(750^2 - x[i]^2) } yfunction # determine which proportion of points lie within quarter circle count1 <- 0 for (i in 1:n) { if(y[i] - yfunction[i] <=0) count1 <- count1 + 1 } cat("proportion of area irrigated =", count1/n, "\n") plot(x,y, main="picture of stochastic generated points") points(x,yfunction)