%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Example for the AR Sampler, following KPT, Ex. 11.22 and 11.24
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rand('state',37); % set arbitrary seed for uniform draws
randn('state',37); % set arbitrary seed for normal draws
tic; % start stop watch
[fid]=fopen('c:\klaus\aaec6564\mlab\logs\mod14_AR.txt','w');
if fid==-1;
error('File could not be opened');
else;
disp('File opened successfully');
end;
R=5000; %desired number of accepted draws
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ex1: Approximating the triangular over [-1,1] via a U[-1,1]
fprintf(fid,'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n');
fprintf(fid,'AR for triang(-1,1) via U(-1,1) \n');
fprintf(fid,'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n');
fprintf(fid,'\n');
fprintf(fid,'\n');
M1=2; %"Mwiggle - see lecture notes"
a=-1;
b=1;
keep=0; %running counter for kept draws
keepmat1=zeros(1,R);
i=0; %"i" will count total number of draws, accepted or not
while keep