function [w,f] = findMin(funObj,w,maxEvals,alpha,gamma)

[f,g] = funObj(w);
funEvals = 1;

t = 1; 
y = w;
while 1
	
    if funEvals > 1 
        tp = (1 + sqrt(1+4*t^2))/2;
	y = w + ((t-1)/tp)*(w-w_old);
	t = tp;
	[f,g] = funObj(y);
	funEvals = funEvals+1;
    end
    
	w_old = w;
	
	wp = y - alpha*g; 
	[fp,gp] = funObj(wp);
	funEvals = funEvals+1;
	
	while fp > f - gamma*alpha*g'*g
		fprintf('Backtracking...\n');
		alpha = alpha^2*g'*g/(2*(fp + g'*g*alpha - f));
		wp = y - alpha*g; 
		[fp,gp] = funObj(wp);
		funEvals = funEvals+1;
	end
	
      	w = wp;
	
	optCond = norm(g,'inf');
	fprintf('%6d %15.5e %15.5e %15.5e\n',funEvals,alpha,f,optCond);
	
	if optCond < 1e-2
		break;
	end
	
	if funEvals >= maxEvals
		break;
    end
	
end
