Hi,
I have this algorithm, but I am not too keen on the many if-statements.
Can someone see if this function can be written in a cleaner way?
rand('twister',101)
n = 10;
f = A.^(0:n)./factorial(0:n);
f = f/sum(f);
n = 10000;
Xi = 2;
X = zeros(1,n);
for i =1:n,
dXi = (-1)^round(rand);
Yi = Xi + dXi;
if Yi > 0 & Yi <= length(f),
if f(Yi) >= f(Xi),
X(i) = Yi;
Xi = Yi;
else
if rand <= f(Yi)/f(Xi),
X(i) = Yi;
Xi = Yi;
else
X(i) = Xi;
end
end
end
X(i) = Xi;
end