% S. S. Singh, CUED, Oct. 2007
% script file for Example Sheet 1, Question 4, 4F7

d=.1; % d is delta in question
R=[1 d; d 1];
p=(1+d)*[1 1]';  % this ensures hopt =[ 1 1]' irrespective of d

mu=.1
H=[];
hopt=inv(R)*p
h=[ 0.3 0]';
for i=1:100
   h=h-mu*(R*h-p);
   H=[H,h-hopt];
end

% Uncomment to plot
% subplot(2,1,1)
% hold on
% plot(log(abs(H(1,:)))','r')
% 
% subplot(2,1,2)
% hold on
% plot(log(abs(H(2,:)))','r')