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

3 ビュー (過去 30 日間)

コメント済み: Walter Roberson 2021 年 7 月 9 日
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 = [] ;
end
r0 = [2.5 5 0 0];
ob =@(r)(r(1)-3).^2+(r(2)-4).^2+(r(3)-0.18).^2;
fun=@(r)@nonlcon;
[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)
fun=@(r)@nonlcon;
Error fmincon (Line 654)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Error jisuan (Line 11)
[x,fval,exitflag,output] = fmincon(ob,r0,[],[],[],[],[],[],fun)

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

### 採用された回答

Walter Roberson 2021 年 7 月 8 日
fun=@nonlcon;
##### 4 件のコメント表示非表示 3 件の古いコメント
Walter Roberson 2021 年 7 月 9 日
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.

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

### その他の回答 (1 件)

Fangjun Jiang 2021 年 7 月 8 日
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()
##### 2 件のコメント表示非表示 1 件の古いコメント
Fangjun Jiang 2021 年 7 月 8 日
@Steven Lord, thank you for the note! I didn't know it and learned this today!

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

### Community Treasure Hunt

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

Start Hunting!

Translated by