"nonlincon" part of the "fmincon" function in the optimization toolbox

3 ビュー (過去 30 日間)
Itachi
Itachi 2012 年 8 月 18 日
Hi guys, I want to create the "nonlincon' part of the "fmincon" function. I want to be able to call other variables in the nonlincon function like this:
function [c,ceq]=nonlincon(x,variable1,variable2,...,variableN)
but it gives this error:
Error in fmincon (line 681)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation. FMINCON cannot
continue.
Please help me out, thanks in advance.

採用された回答

Elizabeth
Elizabeth 2012 年 8 月 18 日
What if you globalize the variables that you want to define in the nonlcon function. You would write global variable1.. global variableN in both nonlcon and your main program.

その他の回答 (1 件)

Alan Weiss
Alan Weiss 2012 年 8 月 22 日
You will probably be happier in the long run if you include your extra variables in a function handle or nested function rather than as global variables. See the documentation on passing extra parameters.
Alan Weiss
MATLAB mathematical toolbox documentation

カテゴリ

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