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

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

while 1

    d = g;
    
	wp = w - alpha*d;
	[fp,gp] = funObj(wp);
	funEvals = funEvals+1;
	
	while fp > f - gamma*alpha*g'*d
		fprintf('Backtracking...\n');
		alpha = alpha^2*g'*d/(2*(fp + g'*d*alpha - f));
		
		wp = w - alpha*d;
		[fp,gp] = funObj(wp);
		funEvals = funEvals+1;
	end
	
	f_old = f;
	g_old = g; 
	w = wp;
	f = fp;
	g = gp;
	
	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
