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일

2 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 3월 27일

댓글:

2020년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by