% 
% function jac=myjacobian(fname,x,ob)
%  returns the numeric jacobian of the fnuction fname, around vector
%  x with extra input ob;
% By default this is a one sided differentiation with step 1e-6;
% Gianni Lombardo 2009
function jac=myjacobian(fname,x,ob)

jac=[];
n=length(x);
progress('init');
e=eye(n)*1e-10;
tic;
eval([' fstar = ',fname,'(x,ob);']);
tmp=toc;
tottime=tmp*n;
for i=1:n
%      eval([' jac(:,i)=(',fname, '(x+e(:,i),ob)+' , fname ,'
%      (x-e(:,i),ob)-2*fstar)/e(i,i)^2;']);% two sided
     eval([' jac(:,i)=(',fname, '(x+e(:,i),ob)-fstar)/e(i,i);']);

progress(i/n,sprintf('iteration %i of %i; Remaining time: sec %2.2f\n',i,n,tottime-tmp*i));

end

return

    