Page 292 - MATLAB an introduction with applications
P. 292
Optimization ——— 277
%solve for min
disp(‘(derivative) d(f(x))/dx= -3*x+16.5’)
disp(‘Thus minimum is x=–16.5/3 ~ 5.5’)
disp(‘Second derivative d2(f(x))/d2x=–3<0’)
disp(‘Thus no absolute minimum’)
Example E5.5: Use Powell’s method to find the minimum of the function
2 2
f = 120(y – x ) + (1 – x) 2
Start with (–1, 1).
Solution:
function y = fex3_17(X)
y = 120*(X(2)–X(1)^2)^2+(1–X(1))^2;
>> global X FUNC
>> FUNC = @fex3_17;
>> X=[–1.0,1.0];
>> [xMin,fMin,numCycles]=powell
xMin =
1.0000
1.0000
fMin =
4.8369e–021
numCycles =
12
function [xMin,fMin,nCyc] = powell(h,tol)
% Powell’s method
% h=initial search increment=0.1
% tol=error tolerance=1.0e–6
% X=starting point
% FUNC=function that returns f
% xMin=minimum point
% fMin=miminum value of f
% nCyc=number of cycles to convergence
global X FUNC V
if nargin <2; tol=1.0e–6; end
if nargin <1; h=0.1; end
if size(X,2)>1; X=X’; end
n = length(X);
df = zeros(n,1);