% file name: goldmin.m %minimization golden section serch %Prof. Reyolando Brasil abril 2021 % % xL, xU = lower and upper bounds xL=0; xU=4; % es = desired relative error (%) es=0.0001; % ea = present relative error (%) % maxit = maximum number of iterations maxit=100; % x = location of minimum %fx = minimum value phi=(1+sqrt(5))/2; iter=0; while(1) d=(phi-1)*(xU-xL); x1=xL+d; x2=xU-d; if ftest(x1)=maxit, break,end end disp('Location of minimum') xopt disp('Minimum value of function') fx=ftest(xopt) disp('Number of iterations') iter