# Metodo Monte Carlo int=function(func,from,to,max,n) { curve(func(x),col="red",from,to) i=0 for (k in 1:n) { y=runif(1,0,max) x=runif(1,from,to) points(x,y,pch=20,col="green") if (y int(func=sin,from=0,to=pi,max=1,100000) # [1] 2.004210 # Esempio 2: # > f=function(x) x^2 # > int(f,1,2,4,100000) # [1] 2.33428