Page 366 - Applied Numerical Methods Using MATLAB
P. 366
MATLAB BUILT-IN ROUTINES FOR OPTIMIZATION 355
1
Chebyshev
0.8 f (x) = 1
1 + 8x 2
0.6 fminimax
0.4
least squares
0.2
0
−0.2
−2 −1.5 −1 −0.5 0 0.5 1 1.5 2
Figure 7.14 Approximation of a curve by a second-degree polynomial function based on the
minimax, least-squares, and Chebyshev methods.
the same as the (unconstrained) least squares solution obtained by using the
routine “lsqnonlin()”.
ž Another MATLAB built-in routine “lsqnonneg()” gives us a nonnegative
LS (NLS) solution to the problem (7.3.8).
%nm732_2: uses fminimax() for a vector-valued objective ftn f(x)
clear, clf
f = inline(’1./(1+8*x.*x)’,’x’);
f73221 = inline(’abs(polyval(a,x) - fx)’,’a’,’x’,’fx’);
f73222 = inline(’polyval(a,x) - fx’,’a’,’x’,’fx’);
N = 2; % the degree of approximating polynomial
a0 = zeros(1,N + 1); %initial guess of polynomial coefficients
xx = -2+[0:200]’/50; %intermediate points
fx = feval(f,xx); % and their function values f(xx)
ao_m = fminimax(f73221,a0,[],[],[],[],[],[],[],[],xx,fx) %fminimax sol
for n = 1:N+1, C(:,n) = xx.^(N + 1 - n); end
ao_ll = lsqlin(C,fx) %linear LS to minimize (Ca - fx)^2 with no constraint
ao_ln = lsqnonlin(f73222,a0,[],[],[],xx,fx) %nonlinear LS
c2 = cheby(f,N,-2,2) %Chebyshev polynomial over [-2,2]
plot(xx,fx,’:’, xx,polyval(ao_m,xx),’m’, xx,polyval(ao_ll,xx),’r’)
hold on, plot(xx,polyval(ao_ln,xx),’b’, xx,polyval(c2,xx),’--’)
axis([-2 2 -0.4 1.1])
7.3.3 Linear Programming (LP)
The linear programming (LP) scheme implemented by the MATLAB built-in
routine
"[xo,fo] = linprog(f,A,b,Aeq,Beq,l,u,x0,options)"
is designed to solve an LP problem, which is a constrained minimization problem
as follows.
T
Min f(x) = f x (7.3.10a)
subject to Ax ≤ b, A eq x = b eq , and l ≤ x ≤ u (7.3.10b)