匿名函数在优化中的应用
例1求下列函数的最小值
用匿名函数表达目标函数f(x)如下:
f=@(x)3*x(1)^2+2*x(1)*x(2)+x(2)^2;
x0=[1,1]; %初始值
[x,fval]=fminunc(f,x0)
Local minimum found.
Optimization completed because the size of the gradient is less than
the default value of the optimality tolerance.
<stopping criteria details>
x =
1.0e-06 *
1 列
0.254083674796170
2 列
-0.202933921209731
fval =
1.317333248878051e-13