Page 323 - MATLAB an introduction with applications
P. 323
308 ——— MATLAB: An Introduction with Applications
The program is as follows:
global X V
X=[–1;1]; %STARTING POINT
N=length(X);% number of design variables
df=zeros(N,1);% decreases of f stored here
u=eye(N); % columns of u store search directions V
n=30; % Number of cycles
for j=1:n
xold=X;
fold=90*(xold(2)–xold(1)^2)^2+(1–xold(1))^2;
% 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));
The function with file name ‘fline.m’ used is as follows:
function z=fline(s)
global X V
b1=V(1);
b2=V(2);
a1=X(1);a2=X(2);