Error with Fmincon nonlinear constraint
1 次查看(过去 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
0 个评论
采纳的回答
Alan Weiss
2020-3-30
2 个评论
Alan Weiss
2020-3-30
Since it helped, please "accept" the answer.
Alan Weiss
MATLAB mathematical toolbox documentation
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!