MATLAB Answers

Insufficient number of outputs from right hand side of equal sign to satisfy assignment

4 views (last 30 days)
I've seen other questions and answers on this topic, but could not find the answer to my problem.
function [c,ceq] = nonlcon(r)
s = [1 2 0.18 0.0997;
2 3 0.3 0.102;
3 4 0.5 0.1045;
4 5 0.5 0.1064];
vv = 6;
ceq(1) = (s(1,1)-r(1)).^2+(s(1,2)-r(2)).^2+(s(1,3)-r(3)).^2-vv.*(s(1,4)-r(4)).^2==0;
ceq(2) = (s(2,1)-r(1)).^2+(s(2,2)-r(2)).^2+(s(2,3)-r(3)).^2-vv.*(s(2,4)-r(4)).^2==0;
ceq(3) = (s(3,1)-r(1)).^2+(s(3,2)-r(2)).^2+(s(3,3)-r(3)).^2-vv.*(s(3,4)-r(4)).^2==0;
ceq(4) = (s(4,1)-r(1)).^2+(s(4,2)-r(2)).^2+(s(4,3)-r(3)).^2-vv.*(s(4,4)-r(4)).^2==0;
c = [] ;
r0 = [2.5 5 0 0];
ob =@(r)(r(1)-3).^2+(r(2)-4).^2+(r(3)-0.18).^2;
[x,fval,exitflag,output] = fmincon(ob,r0,[],[],[],[],[],[],fun)
Why i am getting this error? Hope someone can enlighten me.
Error jisuan>@(r)@nonlcon (Line 10)
Error fmincon (Line 654)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Error jisuan (Line 11)
[x,fval,exitflag,output] = fmincon(ob,r0,[],[],[],[],[],[],fun)

Accepted Answer

Walter Roberson
Walter Roberson on 8 Jul 2021
Walter Roberson
Walter Roberson on 9 Jul 2021
Note that your constraints have four equations in four variables, so they resolve down to two particular solutions. The only question then is whether one of the sets of solutions is better than the other, and the answer to that is No, they are both the same.

Sign in to comment.

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 8 Jul 2021
nonlcon() is a defined function so fun=@nonlcon should be enough. It might be easier if the function has only one return variable. The returned "c" is empty anyway so you might just delete "c" in nonlcon()

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!