%CHECK  computes numerical derivates for lqmle.m and compares them to 
%       analytical derivatives.  The parameter vector, Theta, and 
%       data matrix, ZVAR, are assumed to be in the workspace.


[l,ld]=lqmle_1b(Theta);
del = diag(abs(Theta)*1e-5);
clear d
for i=1:length(Theta);
  lp=lqmle_1b(Theta+del(:,i));
  lm=lqmle_1b(Theta-del(:,i));
  if length(lp)>1;
    d(:,i)=(vec(lp)-vec(lm))/(2*del(i,i));
    [ld(:,i),d(:,i),ld(:,i)./d(:,i)]
  else
    d(i,1)=(lp-lm)/(2*del(i,i));
    ld=ld(:);d=d(:);
    [ld(1:i),d(1:i),ld(1:i)./d(1:i)]
  end
end;
