%script11
% demonstration of the metropolis-hastings algorithm 
fn='wigglyfn'   % this is the function to be optimised
int1=[-10 10] ; int2=[-10 10]; % interval of values for first and second argument of function 
%plots a surface defined by the function (represented by a string) fn  over intervals x in int1 and y in int2
x=int1(1)+.025*(int1(2)-int1(1))*(0:40);
y=int2(1)+.02*(int2(2)-int2(1))*(0:50);
z=[];
for i=1:41
    z=[z ;eval(strcat(fn,'(x(i),y)'))];
end
surf(x,y,z')
figure
w=hastings('wigglyfn',[0 0],5,10000);
plot(w(:,1),w(:,2),'.y')
hold on
contour(x,y,z')


