{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

NonMCAreas

# NonMCAreas - s SSize< as.numeric(ANSWER cat"\n"...

This preview shows page 1. Sign up to view the full content.

#Draws a function y=x^2 from 0 to 1 # FUNC <- function(title,loco) F { op <- par(bg = "white") x <- seq(0,1, len=61) x y <- seq(0,1, len=61) #R needs to know bounds of graphic. plot(x,x^2, type="l", main=title,ylab="Y",xlab="X") p par(op)}#Calculates an Area Using Darts # BULLSEYE<-function() B { cat("\n") cat("*****BULLS EYE*****","\n") cat("The Goal: The area beneath y=x^2 from 0 to 1","\n") a cat(" ","\n") cat("\n") #draw the circle FUNC("Y equal X squared",0) X #Determine the number of darts thrown ANSWER <- readline("What is the sample size? ")
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: s SSize <- as.numeric(ANSWER) cat("\n") ANSWER <- readline("Fire darts one at a time? ") if (substr(ANSWER, 1, 1) == "y") { cnt <- 0 for (i in 1:SSize) { ANSWER <- readline("Hit ENTER to FIRE WHEN READY!") A cat("\n") cat("FIRE!!!\n") c cat("\n") x=runif(1) y=runif(1) points(x,y) if (y<x^2) cnt=cnt+1 } pct <- cnt/SSize } else { xdarts<-runif(SSize) ydarts<-runif(SSize) points(xdarts,ydarts) p #darts cnt <- 0 for (i in 1:SSize) { if (ydarts[i]<xdarts[i]^2) cnt=cnt+1 c } pct<-cnt/SSize } return(pct) r }BULLSEYE()...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online