MATLAB匿名函数的应用5

来源:互联网 发布:js中文转码函数 编辑:程序博客网 时间:2024/05/29 12:51

匿名函数在优化中的应用

例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 thanthe default value of the optimality tolerance.<stopping criteria details>x =   1.0e-06 *  10.254083674796170  2 列  -0.202933921209731fval =     1.317333248878051e-13