2016-12-24 118 views
0

https://www.mathworks.com/help/optim/examples/banana-function-minimization.htmlMATLAB優化工具箱例如

fun = @(x)(100*(x(2) - x(1)^2)^2 + (1 - x(1))^2); 
options = optimset('OutputFcn',@bananaout,'Display','off'); 
x0 = [-1.9,2]; 
[x,fval,eflag,output] = fminsearch(fun,x0,options); 
title 'Rosenbrock solution via fminsearch' 
Fcount = output.funcCount; 
disp(['Number of function evaluations for fminsearch was ',num2str(Fcount)]) 
disp(['Number of solver iterations for fminsearch was ',num2str(output.iterations)]) 

什麼是@bananaout這裏?

這是給我下面的錯誤,

??? Error using ==> feval 
Attempt to execute SCRIPT bananaout as a function: 
C:\Users\admin\Desktop\bananaout.m 

Error in ==> callAllOptimOutputFcns at 12 
    stop(i) = feval(OutputFcn{i},xOutputfcn,optimValues,state,varargin{:}); 

Error in ==> fminsearch>callOutputAndPlotFcns at 464 
      stop = callAllOptimOutputFcns(outputfcn,xOutputfcn,optimValues,state,varargin{:}) 
      || stop; 

Error in ==> fminsearch at 199 
    [xOutputfcn, optimValues, stop] = 
    callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'init',itercount, ... 

Error in ==> test_optim at 9 
[x,fval,eflag,output] = fminsearch(fun,x0,options) 

回答

1

按照商務部,Output Functions被優化在每個時間步長叫,使您能夠做這樣的事情的情節優化的進度。

在你的情況下,你會得到一個錯誤,因爲bananaout似乎是一個腳本,當它需要是一個函數(具體輸入 - 請參閱文檔的細節)。您是否碰巧將示例代碼保存在名爲bananaout的腳本中?如果是這樣,請重命名該腳本。

你可以看到,你有被執行所謂bananaout所有M代碼列表如下:

>> which bananaout -all

其中之一將是例子應該調用該函數,而另一個將是您創建並需要重命名/刪除的那個。