If Xm~uniform(-25,25),Ym~uniform(-25,25) and r~uniform(0,25), θ~uniform(0,2π) and Xf=rcosθ, Yf=rsinθ.
I want to use a for loop to create 5000 independent variables of point (Xm,Ym) and (Xf,Yf) then calculate the distance between the two points. i know how to calculate the distance between points but creating 5000 realisations of (Xm,Ym) and (Xf,Yf) I am finding tricky. here is my attempt:
Now for Xf,Yf I took a similar approach to Xm,Ym
for (i in 1:5000) { res=c() repeat{ Xm=runif(1,min=-25,max=25) Ym=runif(1,min=-25,max=25) if(Xm**2+Ym**2<=25**2) res=rbind(res,data.frame(Xm,Ym)) break { res=rbind(res,data.frame(Xm,Ym)) } for (i in 1:5000) { res=c() repeat{ R=runif(1,min=0,max=25) 0=runif(1,min=0,max=2*pi) Xf=Rcos(0) Yf=Rsin(0) Yf=runif(1,min=-25,max=25) if(Xf**2+Yf**2<=25**2) res=rbind(res,data.frame(Xf,Yf)) break { res=rbind(res,data.frame(Xf,Yf)) } D=sqrt((Xm-Xf)**2+(Ym-Yf)**2))
sample()to get 5000 points of Xm or in the samerunif(n=5000)