I am trying to write a function circle_MC that takes the length of radius and the number of simulations (N) as an input and returns the area enclosed by a circle.
For doing that, I create a numeric vector and change it to "1", if the point is inside the circle, i.e. the ifelse statement holds. My code so far:
circle_MC <- function(r, N)
{
inside <- numeric(N),#only zeroes
x_sim[i] <- runif(N, min = -r, max = r),
y_sim[i] <- runif(N, min = -r, max = r),
inside <- ifelse(x_sim^2[i] + y_sim^2[i] <= r, 1, 0),
area <- (sum(inside)/length(inside)*4)
return(area)
}
However, it gives me the error message "Error: unexpected '}' in "}".
I am pretty new to R and would love to understand where my mistake is.