Fmincon Too many input arguments

5 ビュー (過去 30 日間)
Joseph Cullen
Joseph Cullen 2015 年 7 月 4 日
コメント済み: Walter Roberson 2015 年 7 月 6 日
This is driving me crazy. I have almost this exact line of code in another program and it works perfectly.
bellman_handle = @(capnext)bellmanRHScont(capnext,transd(j,:), c , x(i), start, beta, theta(j), b, mc);
[action,value]=fmincon(bellman_handle,1,[],[],[],[],0,k,[],[],options);
I am using an anonymous function, but when I run the code I get the following error. Any ideas?
Error using
@(capnext)bellmanRHScont(capnext,transd(j,:),c,x(i),start,beta,theta(j),b,mc)
Too many input arguments.
Error in fmincon (line 564)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in testmodelcont (line 100)
[action,value]=fmincon(bellman_handle,1,[],[],[],[],0,k,[],[],options);
Caused by:
Failure in initial user-supplied objective
function evaluation. FMINCON cannot continue.

採用された回答

Walter Roberson
Walter Roberson 2015 年 7 月 4 日
You did not show us the header for bellmanRHScont so we do not know how many inputs it expects. You are passing in 9 inputs to it.
You are passing 11 inputs to fmincon(). fmincon() is not documented as accepting more than 10 inputs. For historical reasons, any inputs past the 10th will be passed as extra parameters to the function, so two parameters would be passed to your function handle that expects only 1.
You should re-count the number of [] you have. You might wish to assign the various [] to variable names to make it clearer which [] corresponds to which parameter.
  2 件のコメント
Joseph Cullen
Joseph Cullen 2015 年 7 月 5 日
Good call. I didn't realize that any extra parameters would be passed to the function. I have two minimizers that I use: fmincon and knitro. Knitro has 11 inputs and fmincon has 10. I had one extra set of empty brackets in the fmincon call. Not an easy difference to spot.
knitromatlab(bellman_handle,1,[],[],[],[],0,k,[],[],options);
incorrect: fmincon(bellman_handle,1,[],[],[],[],0,k,[],[],options);
correct: fmincon(bellman_handle,1,[],[],[],[],0,k,[],options);
Walter Roberson
Walter Roberson 2015 年 7 月 6 日
Sounds like a good reason to use variables that have been assigned [] in order to document the purpose of each []

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by