How do i iterate functions until convergence in R? I am looking to iterate until convergence but I am not sure how i should code it.
A simple similar example is something like
$X_0=5 ,  Y_0=3$
for $n=1,2..$
$P_n=X_{n-1}-Y_{n-1}$
$Y_n=3P_n$
$X_n=P_n+Y_n$
and end when it converges.
I have seen that for the repeat loop it loops indefinitely with an exit condition but I am unsure how i can word the iterations  within R and how to word the exit condition for convergence. Any references or help would be appreciated.
Generally you want to check that the change in your value of interest becomes very small, eg $abs(X_n - X_{n-1}) &lt; eps$ where eps is a small number like 0.0001.