Area Beneath Y=X^2 from 0 to 1

Area Beneath Y=X^2 from 0 to 1 - s SSize <-...

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

View Full Document Right Arrow Icon
#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) < y <- seq(0,1, len=61) #plot the function plot(x,x^2, type="l", main=title,ylab="Y",xlab="X") m par(op) }#Calculates an Area Using Darts # BULLSEYE<- function() f { cat("\n") cat("*****BULLS EYE*****","\n") cat("The Goal: Calculate the area between the function and the x axis from x=0 to b x=1","\n") x cat("\n") #draw the circle FUNC("Y equal X squared",0) e #Determine the number of darts thrown ANSWER <- readline("What is the sample size? ")
Background image of page 1
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") { fx <- NULL for (i in 1:SSize) { ANSWER <- readline("Hit ENTER to FIRE WHEN READY!") A cat("\n") cat("FIRE!!!\n") cat("\n") c x=runif(1) y=x^2 lines(c(x,x),c(0,y)) fx <- c(fx,y) } pct <- mean(fx) } else e { xdarts<-runif(SSize) ydarts<-xdarts^2 for (i in 1:SSize) {lines(c(xdarts[i],xdarts[i]),c(0,ydarts[i]))} { fx<-ydarts pct<-mean(fx) } return(pct) r } BULLSEYE()...
View Full Document

This note was uploaded on 11/16/2010 for the course STAT 340 taught by Professor Xu(sunny)wang during the Spring '09 term at Waterloo.

Ask a homework question - tutors are online