-
Notifications
You must be signed in to change notification settings - Fork 7
/
opt04_run.m
72 lines (61 loc) · 2.25 KB
/
opt04_run.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%% OPT04_RUN
%
% Modified:
%
% 26 January 2008
%
%---------------------------------------------------------------------
% Running the Himmelblau function.
%---------------------------------------------------------------------
fprintf('---------------------------------------------------------\n')
fprintf('Running testcase_4: Himmelblau\n')
fprintf('---------------------------------------------------------\n')
fname = 'opt04_fgh';
options = [];
options.verbose = 0;
options.step_tolerance = 1.e-11;
options.gradient_tolerance = 1.e-11;
options.max_iterations = 15;
x0 = [ 1; 1];
%
% Run with Newton method.
%
fprintf('Newton method:\n')
options.method = 'newton';
options.globalization = 'none';
x = entrust(fname, x0, options);
fprintf('Newton method produced (%10.7e,%10.7e)\n\n',x(1),x(2))
f = opt04_fgh ( x, 'f' );
fprintf('Value of F(X) = %10.7e\n', f );
%
% Run with secant method.
%
fprintf ( '\n' );
fprintf ( 'Use the secant method:\n')
fprintf ( ' (Algorithm likely to fail!)\n' );
fprintf ( '\n' );
options.method = 'secant';
options.initial_hessian = [ 0., 1. ; 1., 0. ];
x = entrust(fname, x0, options);
fprintf('BFGS method produced (%10.7e,%10.7e)\n\n',x(1),x(2))
f = opt04_fgh ( x, 'f' );
fprintf('Value of F(X) = %10.7e\n\n', f );
%---------------------------------------------------------------------
% Test Gauss-Newton strategies.
%---------------------------------------------------------------------
fprintf('---------------------------------------------------------\n')
fprintf('Running testcase_4 as least squares problem: \n')
fprintf('---------------------------------------------------------\n')
fname = 'opt04_rj';
options = [];
options.verbose = 0;
options.method = 'gauss_newton';
options.step_tolerance = 1.e-15;
options.globalization = 'none';
options.gradient_tolerance = 1.e-10;
options.max_iterations = 40;
x0 = [1,1];
x = entrust(fname, x0, options );
fprintf('Gauss-Newton produced (%10.7e, %10.7e)\n\n',x(1),x(2))
[ res, jac ] = opt04_rj ( x, 'f' );
fprintf('Norm of RES(X) = %10.7e\n', norm ( res ) );