| [5443b1] | 1 | % Demo program for levmar's MEX-file interface | 
|---|
|  | 2 | % Performs minimization of several test problems | 
|---|
|  | 3 |  | 
|---|
|  | 4 | format long; | 
|---|
|  | 5 |  | 
|---|
|  | 6 | % Unconstrained minimization | 
|---|
|  | 7 |  | 
|---|
|  | 8 | % fitting the exponential model x_i=p(1)*exp(-p(2)*i)+p(3) of expfit.c to noisy measurements obtained with (5.0 0.1 1.0) | 
|---|
|  | 9 | p0=[1.0, 0.0, 0.0]; | 
|---|
|  | 10 | x=[5.8728, 5.4948, 5.0081, 4.5929, 4.3574, 4.1198, 3.6843, 3.3642, 2.9742, 3.0237, 2.7002, 2.8781,... | 
|---|
|  | 11 | 2.5144, 2.4432, 2.2894, 2.0938, 1.9265, 2.1271, 1.8387, 1.7791, 1.6686, 1.6232, 1.571, 1.6057,... | 
|---|
|  | 12 | 1.3825, 1.5087, 1.3624, 1.4206, 1.2097, 1.3129, 1.131, 1.306, 1.2008, 1.3469, 1.1837, 1.2102,... | 
|---|
|  | 13 | 0.96518, 1.2129, 1.2003, 1.0743]; | 
|---|
|  | 14 |  | 
|---|
|  | 15 | options=[1E-03, 1E-15, 1E-15, 1E-20, 1E-06]; | 
|---|
|  | 16 | % arg demonstrates additional data passing to expfit/jacexpfit | 
|---|
|  | 17 | arg=[40]; | 
|---|
|  | 18 |  | 
|---|
|  | 19 | [ret, popt, info]=levmar('expfit', 'jacexpfit', p0, x, 200, options, arg); | 
|---|
|  | 20 | disp('Exponential model fitting (see also ../expfit.c)'); | 
|---|
|  | 21 | popt | 
|---|
|  | 22 |  | 
|---|
|  | 23 |  | 
|---|
|  | 24 | % Meyer's (reformulated) problem | 
|---|
|  | 25 | p0=[8.85, 4.0, 2.5]; | 
|---|
|  | 26 |  | 
|---|
|  | 27 | x=[]; | 
|---|
|  | 28 | x(1:4)=[34.780, 28.610, 23.650, 19.630]; | 
|---|
|  | 29 | x(5:8)=[16.370, 13.720, 11.540, 9.744]; | 
|---|
|  | 30 | x(9:12)=[8.261, 7.030, 6.005, 5.147]; | 
|---|
|  | 31 | x(13:16)=[4.427, 3.820, 3.307, 2.872]; | 
|---|
|  | 32 |  | 
|---|
|  | 33 | options=[1E-03, 1E-15, 1E-15, 1E-20, 1E-06]; | 
|---|
|  | 34 | % arg1, arg2 demonstrate additional dummy data passing to meyer/jacmeyer | 
|---|
|  | 35 | arg1=[17]; | 
|---|
|  | 36 | arg2=[27]; | 
|---|
|  | 37 |  | 
|---|
|  | 38 | %[ret, popt, info]=levmar('meyer', 'jacmeyer', p0, x, 200, options, arg1, arg2); | 
|---|
|  | 39 |  | 
|---|
|  | 40 | %[ret, popt, info, covar]=levmar('meyer', 'jacmeyer', p0, x, 200, options, arg1, arg2); | 
|---|
|  | 41 | [ret, popt, info, covar]=levmar('meyer', p0, x, 200, options, 'unc', arg1, arg2); | 
|---|
|  | 42 | disp('Meyer''s (reformulated) problem'); | 
|---|
|  | 43 | popt | 
|---|
|  | 44 |  | 
|---|
|  | 45 |  | 
|---|
|  | 46 | % Osborne's problem | 
|---|
|  | 47 | p0=[0.5, 1.5, -1.0, 1.0E-2, 2.0E-2]; | 
|---|
|  | 48 |  | 
|---|
|  | 49 | x=[8.44E-1, 9.08E-1, 9.32E-1, 9.36E-1, 9.25E-1, 9.08E-1, 8.81E-1,... | 
|---|
|  | 50 | 8.5E-1, 8.18E-1, 7.84E-1, 7.51E-1, 7.18E-1, 6.85E-1, 6.58E-1,... | 
|---|
|  | 51 | 6.28E-1, 6.03E-1, 5.8E-1, 5.58E-1, 5.38E-1, 5.22E-1, 5.06E-1,... | 
|---|
|  | 52 | 4.9E-1, 4.78E-1, 4.67E-1, 4.57E-1, 4.48E-1, 4.38E-1, 4.31E-1,... | 
|---|
|  | 53 | 4.24E-1, 4.2E-1, 4.14E-1, 4.11E-1, 4.06E-1]; | 
|---|
|  | 54 |  | 
|---|
|  | 55 |  | 
|---|
|  | 56 | options=[1E-03, 1E-15, 1E-15, 1E-20, 1E-06]; | 
|---|
|  | 57 |  | 
|---|
|  | 58 | [ret, popt, info, covar]=levmar('osborne', 'jacosborne', p0, x, 200, options); | 
|---|
|  | 59 | %[ret, popt, info, covar]=levmar('osborne', p0, x, 200, options, 'unc'); | 
|---|
|  | 60 | disp('Osborne''s problem'); | 
|---|
|  | 61 | popt | 
|---|
|  | 62 |  | 
|---|
|  | 63 |  | 
|---|
|  | 64 | % Linear constraints | 
|---|
|  | 65 |  | 
|---|
|  | 66 | % Boggs-Tolle problem 3 | 
|---|
|  | 67 | p0=[2.0, 2.0, 2.0, 2.0, 2.0]; | 
|---|
|  | 68 | x=[0.0, 0.0, 0.0, 0.0, 0.0]; | 
|---|
|  | 69 | options=[1E-03, 1E-15, 1E-15, 1E-20]; | 
|---|
|  | 70 | adata=[]; | 
|---|
|  | 71 |  | 
|---|
|  | 72 | A=[1.0, 3.0, 0.0, 0.0, 0.0; | 
|---|
|  | 73 | 0.0, 0.0, 1.0, 1.0, -2.0; | 
|---|
|  | 74 | 0.0, 1.0, 0.0, 0.0, -1.0]; | 
|---|
|  | 75 | b=[0.0, 0.0, 0.0]'; | 
|---|
|  | 76 |  | 
|---|
|  | 77 | [ret, popt, info, covar]=levmar('bt3', 'jacbt3', p0, x, 200, options, 'lec', A, b, adata); | 
|---|
|  | 78 | disp('Boggs-Tolle problem 3'); | 
|---|
|  | 79 | popt | 
|---|
|  | 80 |  | 
|---|
|  | 81 |  | 
|---|
|  | 82 | % Box constraints | 
|---|
|  | 83 |  | 
|---|
|  | 84 | % Hock-Schittkowski problem 01 | 
|---|
|  | 85 | p0=[-2.0, 1.0]; | 
|---|
|  | 86 | x=[0.0, 0.0]; | 
|---|
|  | 87 | lb=[-realmax, -1.5]; | 
|---|
|  | 88 | ub=[realmax, realmax]; | 
|---|
|  | 89 | options=[1E-03, 1E-15, 1E-15, 1E-20]; | 
|---|
|  | 90 |  | 
|---|
|  | 91 | [ret, popt, info, covar]=levmar('hs01', 'jachs01', p0, x, 200, options, 'bc', lb, ub); | 
|---|
|  | 92 | disp('Hock-Schittkowski problem 01'); | 
|---|
|  | 93 | popt | 
|---|
|  | 94 |  | 
|---|
|  | 95 |  | 
|---|
|  | 96 | % Box and linear constraints | 
|---|
|  | 97 |  | 
|---|
|  | 98 | % Hock-Schittkowski modified problem 52 (#1) | 
|---|
|  | 99 | p0=[2.0, 2.0, 2.0, 2.0, 2.0]; | 
|---|
|  | 100 | x=[0.0, 0.0, 0.0, 0.0]; | 
|---|
|  | 101 | lb=[-0.09, 0.0, -realmax, -0.2, 0.0]; | 
|---|
|  | 102 | ub=[realmax, 0.3, 0.25, 0.3, 0.3]; | 
|---|
|  | 103 | A=[1.0, 3.0, 0.0, 0.0, 0.0; | 
|---|
|  | 104 | 0.0, 0.0, 1.0, 1.0, -2.0; | 
|---|
|  | 105 | 0.0, 1.0, 0.0, 0.0, -1.0]; | 
|---|
|  | 106 | b=[0.0, 0.0, 0.0]'; | 
|---|
|  | 107 | options=[1E-03, 1E-15, 1E-15, 1E-20]; | 
|---|
|  | 108 |  | 
|---|
|  | 109 | [ret, popt, info, covar]=levmar('modhs52', 'jacmodhs52', p0, x, 200, options, 'blec', lb, ub, A, b); | 
|---|
|  | 110 | disp('Hock-Schittkowski modified problem 52 (#1)'); | 
|---|
|  | 111 | popt | 
|---|
|  | 112 |  | 
|---|
|  | 113 | % Schittkowski modified problem 235 | 
|---|
|  | 114 | p0=[-2.0, 3.0, 1.0]; | 
|---|
|  | 115 | x=[0.0, 0.0]; | 
|---|
|  | 116 | lb=[-realmax, 0.1, 0.7]; | 
|---|
|  | 117 | ub=[realmax, 2.9, realmax]; | 
|---|
|  | 118 | A=[1.0, 0.0, 1.0; | 
|---|
|  | 119 | 0.0, 1.0, -4.0]; | 
|---|
|  | 120 | b=[-1.0, 0.0]'; | 
|---|
|  | 121 | options=[1E-03, 1E-15, 1E-15, 1E-20]; | 
|---|
|  | 122 |  | 
|---|
|  | 123 | [ret, popt, info, covar]=levmar('mods235', p0, x, 200, options, 'blec', lb, ub, A, b); | 
|---|
|  | 124 | disp('Hock-Schittkowski modified problem 235'); | 
|---|
|  | 125 | popt | 
|---|
|  | 126 |  | 
|---|
|  | 127 | % Box, linear equation & inequality constraints | 
|---|
|  | 128 | p0=[0.5, 0.5, 0.5, 0.5]; | 
|---|
|  | 129 | x=[0.0, 0.0, 0.0, 0.0]; | 
|---|
|  | 130 | lb=[0.0, 0.0, 0.0, 0.0]; | 
|---|
|  | 131 | ub=[realmax, realmax, realmax, realmax]; | 
|---|
|  | 132 | A=[0.0, 1.0, 4.0, 0.0]; | 
|---|
|  | 133 | b=[1.5]'; | 
|---|
|  | 134 | C=[-1.0, -2.0, -1.0, -1.0; | 
|---|
|  | 135 | -3.0, -1.0, -2.0, 1.0]; | 
|---|
|  | 136 | d=[-5.0, -0.4]'; | 
|---|
|  | 137 |  | 
|---|
|  | 138 | [ret, popt, info, covar]=levmar('modhs76', 'jacmodhs76', p0, x, 200, options, 'bleic', lb, ub, A, b, C, d); | 
|---|
|  | 139 | disp('Hock-Schittkowski modified problem 76'); | 
|---|
|  | 140 | popt | 
|---|