Error with Fmincon nonlinear constraint

21 ビュー (過去 30 日間)
Brian Noiret
Brian Noiret 2020 年 3 月 27 日
コメント済み: Alan Weiss 2020 年 3 月 30 日
Hi! I encounter a problem trying to use fmincon to solve a nonlinear equation system. The message error:
Error in Untitled (line 12)
F=@(n) [n(1) + n(2) + n(3) + n(4) + n(5) + n(6) + n(7) + n(8) + w - n(9);...
Error in fmincon (line 639)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Error in Untitled (line 28)
n=fmincon(@(x)0,x0,[],[],[],[],lb,ub,[[],F],opts);
Caused by:
Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.
Hereunder you can find a simplified version of my code that returns that error as well. This being the first time I use fmincon, I assume I made a basic syntax error, can anyone help me with this?
nIt = 1;
for ii=1:nIt
% K01 = ;
% K02 = ;
% K03 = ;
% K04 = ;
%
% a = ; b = ; c = ;
% u = ; v = ; w = ; x = ; y = ; z = ;
F=@(n) [n(1) + n(2) + n(3) + n(4) + n(5) + n(6) + n(7) + n(8) + w - n(9);...
1 - (n(3) * n(2) / (n(1) * n(4)))/K01;...
1 - (n(7) / (n(8) * n(6)) * n(9) / u)/K02;...
1 - (n(2) / (n(5) * n(6)) * n(9) / u)/K03;...
1 - (n(6)^2 / n(4) * u / n(9))/K04;...
a*x - n(1) - n(3);...
4*(c) + a*y - 2*n(2) - 2*n(4) - n(5) - n(6) - n(7);...
c - n(7) - n(8);...
4*(c) + a*z - 2*n(1) - n(2) - n(3) - n(5) - 3*v];
lb = zeros(1,9); % Lower bound constraint
ub = 10*ones(1,9); %upper bound constraints
rng default % Reproducible initial point
x0 = exprnd(1,9); %initial values
opts = optimoptions(@fmincon,'Algorithm','interior-point','Display','off');
n=fmincon(@(x)0,x0,[],[],[],[],lb,ub,[[],F],opts);
end

採用された回答

Alan Weiss
Alan Weiss 2020 年 3 月 30 日
Try this, as documented:
nlcon = @(x)deal([],F);
Alan Weiss
MATLAB mathematical toolbox documentation
  2 件のコメント
Brian Noiret
Brian Noiret 2020 年 3 月 30 日
Thank you very much, it works very well!
Alan Weiss
Alan Weiss 2020 年 3 月 30 日
Since it helped, please "accept" the answer.
Alan Weiss
MATLAB mathematical toolbox documentation

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by