www.pudn.com > 实验7-线形拟合.rar > examp073.m


% comparing different algorithms: without using gradient vector 
format short e 
x0=[-1.9,2]; 
'---case1: bfgs, hybrid 2,3 poly-------' 
fopt=optimset('LargeScale','off', 'MaxFunEvals',1000); 
[x1,v1,exit1,out1]=fminunc('rosen',x0,fopt) 
pause 
'---case2:  dfp, hybrid 2,3 poly-------' 
fopt=optimset('LargeScale','off','HessUpdate','dfp', 'MaxFunEvals',1000); 
[x2,v2,exit2,out2]=fminunc('rosen',x0,fopt) 
pause 
'---case3: steep, hybrid 2,3 poly-------' 
fopt=optimset('LargeScale','off','HessUpdate','steepdesc', 'MaxFunEvals',1000); 
[x3,v3,exit3,out3]=fminunc('rosen',x0,fopt) 
pause 
'---case4: bfgs, 3rd poly-------' 
fopt=optimset('LargeScale','off','LineSearchType','cubicpoly', 'MaxFunEvals',1000); 
[x4,v4,exit4,out4]=fminunc('rosen',x0,fopt) 
pause 
'---case5:  dfp, 3rd poly-------' 
fopt=optimset('LargeScale','off','HessUpdate','dfp','LineSearchType','cubicpoly', 'MaxFunEvals',1000); 
[x5,v5,exit5,out5]=fminunc('rosen',x0,fopt) 
pause 
'---case6: steep, 3rd poly-------' 
fopt=optimset('LargeScale','off','HessUpdate','steepdesc','LineSearchType','cubicpoly', 'MaxFunEvals',1000); 
[x6,v6,exit6,out6]=fminunc('rosen',x0,fopt) 
pause 
 
'++++    results of solutions ++++++' 
solutions=[x1;x2;x3;x4;x5;x6]' 
funvalues=[v1,v2,v3,v4,v5,v6] 
iterations=[out1.funcCount,out2.funcCount,out3.funcCount,out4.funcCount,out5.funcCount,out6.funcCount]