24 lines
		
	
	
		
			791 B
		
	
	
	
		
			Matlab
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			791 B
		
	
	
	
		
			Matlab
		
	
	
	
	
	
| function [gamma] = gamma_minimized(f, ~, dk, xk)
 | ||
|     % Calculates the step based on minimizing f(xk− γk*dk)
 | ||
|     %
 | ||
|     %
 | ||
|     % f:    Objective function
 | ||
|     % ~:    Gradient function of f - Not used
 | ||
|     % dk:       Current value of selected direction -∇f or -inv{H}*∇f or -inv{H + lI}*∇f
 | ||
|     % xk:   Current point (x,y)
 | ||
| 
 | ||
|     % Define the line search function fmin(g) = f(xk - g * dk)
 | ||
|     fmin = @(g) f(xk(1) + g*dk(1), xk(2) + g*dk(2));
 | ||
| 
 | ||
|     % find g that minimizes fmin
 | ||
|     e = 0.0001;
 | ||
|     l = 0.001;
 | ||
|     [a,b,k,~] = fmin_bisection(fmin, 0, 5, e, l);
 | ||
|     gamma = 0.5*(a(k) + b(k));
 | ||
| 
 | ||
|     % Define the line search function fmin(g) = f(xk - g * dk)
 | ||
|     %fmin = @(g) f(xk(1) - gamma * dk(1), xk(2) - gamma * dk(2));
 | ||
| 
 | ||
|     % find g that minimizes fmin
 | ||
|     %gamma = fminbnd(g, 0, 1);
 | ||
| end |