Page 328 - MATLAB an introduction with applications
P. 328
Optimization ——— 313
fold=7*xold(1)^2+5*xold(2)^2–8*xold(1)*xold(2)–5*xold(1);
% FIRST N line searches record the decrease of f
for i=1:N
V=u(1:N,i);
[s fmin]=fminbnd(‘fline’,0,10);
%Golden section search built in function
df(i)=fold–fmin;
fold=fmin;
X=X+s*V;
end
% LAST LINE SEARCH IN THE CYCLE
V=X–xold;
[s fmin]=fminbnd(‘fline’,0,10);
X=X+s*V;
% IDENTIFY BIGGEST DECREASE OF F
% AND UPDATE SEARCH DIRECTIONS
imax=1; dfmax=df(1);
for i=2:N
if df(i)>dfmax imax=i; dfmax=df(i); end
end
for i=imax:N–1
u(1:N,i)=u(1:N,i+1);
end
u(1:N,N)=V;
end
fprintf(‘Optimum point after %d cycles is\n’,n);
fprintf(‘%f\n%f\n’,X(1),X(2));
Function used is as follows:
function z=fline(s)
global X V
a1=X(1);a2=X(2);
b1=V(1);
b2=V(2);
p1=a1+s*b1;p2=a2+s*b2;
z=7*p1^2+5*p2^2–8*p1*p2–5*p1;
Optimum point after 30 cycles is
0.657916
0.528062
The actual output from MATLAB fminsearch function is
0.6579
0.5263