I have $ f(x)= \frac{5x^4}{32} $ defined on $0<=×<=2$ and I am using rejection sampling with a rectangular bound around the function $[0,2]$ x $[0,2.5]$ since the maximum value is attained at the upper bound at $x=2$. The efficiency should be 1/2.5 ? yet after running my R code where I am simulating from $U~[0,2]$ I get an efficiency of 0.2. ( sorry for any formatting errors, this is my first post)
rejectsim= function(n)
{
t=0
count=0
x=0
while(t
{
count = count + 1 #counts the number of steps
u=runif(1,0,2)
y=runif(1,0,5/2)
f=5/32*u**4
if (y
{
t=t+1
x[t]=u
}
}
print(n/count) #prints the efficiency of the algorithm
x
}