Graphics Programs Reference
In-Depth Information
h
T
2 0 T , we arrive at the following
Letting x
=
θ
and starting with x 0 =
program:
% Example 10.6 (Minimization with Fletcher-Reeves)
global X FUNC DFUNC
FUNC = @fex10
_
_
6; DFUNC = @dfex10
6;
X = [2.0;0.0];
[xMin,fMin,nCyc] = fletcherReeves;
b = 8.0/X(1) - X(1)*tan(X(2));
theta = X(2)*180.0/pi; % Convert into degrees
fprintf('b = %8.5f\n',b)
fprintf('h = %8.5f\n',X(1))
fprintf('theta = %8.5f\n',theta)
fprintf('perimeter = %8.5f\n',fMin)
fprintf('number of cycles = %2.0f',nCyc)
Note that the starting point X and the function handles FUNC (functiondefining
F ) and DFUNC (functiondefining
F ) are declared global . The M-files for the two
functions are
_
functiony=fex10
6(X)
% Function defining F in Example 10.6
y = 8.0/X(1) - X(1)*(tan(X(2)) - 2.0/cos(X(2)));
functiong=dfex10
6(X)
% Function defining grad(F) in Example 10.6
g = zeros(2,1);
g(1) = -8.0/(X(1)ˆ2) - tan(X(2)) + 2.0/cos(X(2));
g(2) = X(1)*(-1.0/cos(X(2)) + 2.0*tan(X(2)))/cos(X(2));
_
The results are(
θ
is in degrees):
>> b = 2.48161
h = 2.14914
theta = 30.00000
perimeter = 7.44484
number of cycles = 5
Search WWH ::




Custom Search