Graphics Programs Reference
In-Depth Information
EXAMPLE 10.4
Use powell to determine the smallest distance from the point(5
,
8) to the curve
xy
=
5.
5) 2
Solution This is a constrained optimizationproblem: minimize F ( x
,
y )
=
( x
+
8) 2 (the square of the distance) subject to the equality constraint xy
( y
5
=
0. The
following program uses Powell's methodwith penalty function:
% Example 10.4 (Powell's method of minimization)
global X FUNC
FUNC = @fex10
4;
X = [1.0; 5.0];
[xMin,fMin,nCyc] = powell;
fprintf('Intersection point = %8.5f %8.5f\n',X(1),X(2))
xy = X(1)*X(2);
fprintf('Constraint x*y = %8.5f\n',xy)
dist = sqrt((X(1) - 5.0)ˆ2 + (X(2) - 8.0)ˆ2);
fprintf('Distance = %8.5f\n',dist)
fprintf('Number of cycles = %2.0f',nCyc)
_
The penaltyis incorporatedinthe M-file of the function to be minimized:
functiony=fex10
4(X)
% Function used in Example 10.4
lam = 1.0; % Penalty multiplier
c = X(1)*X(2) - 5.0; % Constraint equation
distSq = (X(1) - 5.0)ˆ2 + (X(2) - 8.0)ˆ2;
y = distSq + lam*cˆ2;
_
As mentionedbefore, the value of the penalty functionmultiplier
λ
(called lam
in the program)can have profound effects on the result.We chose
λ =
1 (as shown in
the listing of fex10 4 ) with the following result:
>> Intersection point = 0.73307 7.58776
Constraint x*y = 5.56234
Distance = 4.28680
Number of cycles = 7
λ
The small valueof
favored speed of convergence overaccuracy. Since the viola-
tion of the constraint xy
=
5is clearly unacceptable, we ran the program again with
Search WWH ::




Custom Search