# # Estimate pi ?par # Save old parameter values old.par <- par() par(pty="s") # Sets the plot region to be square # Generate random numbers ?runif num.pts <- 5000 x <- runif( num.pts, min=-1, max=1 ) hist(x) y <- runif( num.pts, min=-1, max=1 ) plot(x,y) plot(x,y, xlim=c(-1.5, 1.5), ylim=c(-1.5, 1.5) ) # Plot the circle t <- seq(0, 2*pi, length=100) lines( cos(t), sin(t), lwd=2, col=4 ) # Plot lines abline(v=1, col=2) abline(v=-1, col=3) abline(h=-1, col=4) abline(h=1, col=5) mod <- sqrt(x^2 + y^2) ratio <- sum(mod<1)/length(mod) ratio * 4 par(old.par) # Reset deafult pars # Print the picture as postscript dev.print(postscript, file="testfile.eps")