If anyone cares, this is supposed to be a very simple implementation of a Metropolis algorithm for a uniform distribution. I want to plot the variance of the sampled values as a function of an acceptance ratio, a. The loop in question:
a = 0.1;
u[0] = RandomReal[];
While[a < 2.1,
k = 1;
While[k < 11,
u[k] = RandomReal[];
ut = u[k] - u[k - 1];
r = Exp[-a*ut];
If[r > RandomReal[], k = k + 1, k = k]];
ui = Table[u[k], {k, 10}];
m[a] = Sum[u[k], {k, 1, 10}]/10;
v[a] = Variance[ui];
a = a + 0.1]
This is working for the most part, however v[a] is undefined for a=0.7, 0.9, and a>1.5. The weird part is that if I check v[0.7] manually it returns a value, but if I make a table with v[a],{a,0.1,2,0.1} it shows as undefined at a=0.7. I want to know why I'm having trouble for these a values.