编辑: You—灰機 | 2015-12-11 |
);
disp('
[x,fval,exitflag,output] = fminunc({f,GRAD},x0,OPTIONS);
'
);
[x,fval,exitflag,output] = fminunc({f,GRAD},x0,OPTIONS);
hold off disp('
'
) disp('
Strike any key for menu'
) pause case
3 %当method= 3, 采用最速下降法.clf, xlabel('
x1'
),ylabel('
x2'
), title('
Minimization of the Banana function'
)
35 contour(xx,yy,meshd,conts) hold on plot(-1.9,2,'
ro'
), text(-1.9,2,'
Start Point'
) plot(1,1,'
ro'
), text(1,1,'
Solution'
) OPTIONS=optimset('
LargeScale'
,'
off'
);
OPTIONS = optimset(OPTIONS,'
gradobj'
,'
on'
);
OPTIONS=optimset(OPTIONS,'
HessUpdate'
,'
steepdesc'
);
%将HessUpdate属性设置为steepdesc就使fminunc指令采用最速下降法.GRAD=inline('
[100*(4*x(1)^3-4*x(1)*x(2))+2*x(1)-2;
… 100*(2*x(2)-2*x(1)^2);
banplot6_4(x)]'
);
f=inline('
100*(x(2)-x(1)^2)^2+(1-x(1))^2'
);
disp('
[x,fval,exitflag,output] = fminunc({f,GRAD},x0,OPTIONS);
'
);
[x,fval,exitflag,output] = fminunc({f,GRAD},x0,OPTIONS);
hold off disp('
'
) disp('
Strike any key for menu'
) pause case
4 %当method= 4, 采用单纯形方法.clf,hold on, xlabel('
x1'
),ylabel('
x2'
), title('
Minimization of the Banana function'
) contour(xx,yy,meshd,conts), plot(-1.9,2,'
ro'
), text(-1.9,2,'
Start Point'
) plot(1,1,'
ro'
), text(1,1,'
Solution'
) OPTIONS=optimset('
LargeScale'
,'
off'
);
OPTIONS = optimset(OPTIONS,'
gradobj'
,'
off'
........