[R] Help with functions (iterations)

Letticia Ramlal lramlal at claflin.edu
Sun Sep 30 00:12:43 CEST 2007


Hello: 
I am a bit confused by this problem. Can anyone give me some advice on this I would greatly appreciate it. Thank you for all your help.
 
Need to create a for loop that saves the estimate of pi from each 0f 100 separate iterations and store it in a numeric vector (of length 100). The for loop should be placed in a function that allows the user to vary the sample size, the simulation size, the integration limits and the input function. In addition construct a histogram of the estimates and include a red vertical line at pi.
 
ex1.fcn<-function(x){
h<-4/(1+x^2)
return(h)
}
n=1000
a=0
b=1
my.rand.x=runif(n,min=a,max=b)
pi.MC = ((b-a)/n)*sum(ex1.fcn(my.rand.x))
 



More information about the R-help mailing list