n = 200;
x0 = 10*ones(1,n); %初始迭代点
PTIONS = optimset('LargeScale','on','display','iter','TolFun',1e-8);
[x,fval,exitflag,output] = fminunc(@LargObjFun,x0,PTIONS)```
```clike
function f=LargObjFun(x)
f=0;
n = 200;
for ii=1:n
f=f+(x(ii)-1/ii)^2;
end```
```handlebars
First-order
Iteration Func-count f(x) Step-size optimality
0 201 19884.1 20
1 402 16104.3 0.050025 18
2 603 6.31478e-07 1 0.000287
3 804 1.11396e-14 1 8.9e-10
Local minimum found.
Optimization completed because the size of the gradient is less than
the value of the optimality tolerance.
<stopping criteria details>
x =
列 1 至 14
1.0000 0.5000 0.3333 0.2500 0.2000 0.1667 0.1429 0.1250 0.1111 0.1000 0.0909 0.0833 0.0769 0.0714
列 15 至 28
0.0667 0.0625 0.0588 0.0556 0.0526 0.0500 0.0476 0.0455 0.0435 0.0417 0.0400 0.0385 0.0370 0.0357
列 29 至 42
0.0345 0.0333 0.0323 0.0312 0.0303 0.0294 0.0286 0.0278 0.0270 0.0263 0.0256 0.0250 0.0244 0.0238
列 43 至 56
0.0233 0.0227 0.0222 0.0217 0.0213 0.0208 0.0204 0.0200 0.0196 0.0192 0.0189 0.0185 0.0182 0.0179
列 57 至 70
0.0175 0.0172 0.0169 0.0167 0.0164 0.0161 0.0159 0.0156 0.0154 0.0152 0.0149 0.0147 0.0145 0.0143
列 71 至 84
0.0141 0.0139 0.0137 0.0135 0.0133 0.0132 0.0130 0.0128 0.0127 0.0125 0.0123 0.0122 0.0120 0.0119
列 85 至 98
0.0118 0.0116 0.0115 0.0114 0.0112 0.0111 0.0110 0.0109 0.0108 0.0106 0.0105 0.0104 0.0103 0.0102
列 99 至 112
0.0101 0.0100 0.0099 0.0098 0.0097 0.0096 0.0095 0.0094 0.0093 0.0093 0.0092 0.0091 0.0090 0.0089
列 113 至 126
0.0088 0.0088 0.0087 0.0086 0.0085 0.0085 0.0084 0.0083 0.0083 0.0082 0.0081 0.0081 0.0080 0.0079
列 127 至 140
0.0079 0.0078 0.0078 0.0077 0.0076 0.0076 0.0075 0.0075 0.0074 0.0074 0.0073 0.0072 0.0072 0.0071
列 141 至 154
0.0071 0.0070 0.0070 0.0069 0.0069 0.0068 0.0068 0.0068 0.0067 0.0067 0.0066 0.0066 0.0065 0.0065
列 155 至 168
0.0065 0.0064 0.0064 0.0063 0.0063 0.0062 0.0062 0.0062 0.0061 0.0061 0.0061 0.0060 0.0060 0.0060
列 169 至 182
0.0059 0.0059 0.0058 0.0058 0.0058 0.0057 0.0057 0.0057 0.0056 0.0056 0.0056 0.0056 0.0055 0.0055
列 183 至 196
0.0055 0.0054 0.0054 0.0054 0.0053 0.0053 0.0053 0.0053 0.0052 0.0052 0.0052 0.0052 0.0051 0.0051
列 197 至 200
0.0051 0.0051 0.0050 0.0050
fval =
1.1140e-14
exitflag =
1
output =
包含以下字段的 struct:
iterations: 3
funcCount: 804
stepsize: 7.9471e-04
lssteplength: 1
firstorderopt: 8.8988e-10
algorithm: 'quasi-newton'
message: '↵Local minimum found.↵↵Optimization completed because the size of the gradient is less than↵the value of the optimality tolerance.↵↵<stopping criteria details>↵↵Optimization completed: The first-order optimality measure, 4.239518e-11, is less ↵than options.OptimalityTolerance = 1.000000e-08.↵↵'