MATLAB Answers

0

Please advise - Error 'constraints' Too many output arguments

thitiworada rattanagorn さんによって質問されました 2019 年 1 月 25 日
最新アクティビティ Alan Weiss
さんによって 回答されました 2019 年 1 月 25 日
I have two .m files
function [c,ceq] = constraint(x)
c = [x(1)+x(2)-1;
x(2)-x(1);
x(2)-(1/2);
-x(1);
-x(2)];
ceq = [];
end
and
function f = model_stictionptt(x)
global y uv OP_N PV_N models
%-------load data test--------%
load normalize_data.mat
OP_N=OPN;
PV_N=PVN;
%----Time-----%
TT=0:1:length(PV_N)-1;
Time=TT';
%--estimate MV by He's madel 3 parameter--%
%----parameter-----%
K=1.99;
n=length(OPN);
uv(1)=0;
for i=2:n
u(i)=OP_N(i);
e(i)=u(i)-uv(i-1);
T(i)=Time(i);
if(abs(e(i))> x(1))
uv(i)=uv(i-1)+K*(e(i)-sign(e(i))*x(2));
TT1(i)=T(i);
else
uv(i)=uv(i-1);
TT1(i)=T(i);
end
end
%------ process model by using uv --------%
z = iddata(PV_N,uv',1,'Tstart',0);
%-------ARX model-------------------------%
na=1;
nb=3;
nc=1;
models = arx(z,[na nb nc]);
yy=compare(z,models);
y=yy.OutputData;
%-----cost function-------%
nn=length(PV_N);
f= (1/nn)*sum((y-PV_N).^2);
end
Using fmincon
options = optimoptions('fmincon','Algorithm','sqp');
[x,fval]=fmincon(@model_stictionptt,x0,[],[],[],[],[],[],@constraint,options)
gives the error
Error using constraint
Too many output arguments.
Error in fmincon (line 623)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Error in run_optimizeptt (line 21)
[x,fval]=fmincon(@model_stictionptt,x0,[],[],[],[],[],[],@constraint,options)
Caused by:
Failure in initial nonlinear constraint function evaluation.
FMINCON cannot continue.

  0 件のコメント

サインイン to comment.

1 件の回答

Alan Weiss
回答者: Alan Weiss
2019 年 1 月 25 日
 採用された回答

Do not give bounds and linear inequality constraints as a nonlinear constraint function. Your first two nonlinear constraints should be represented in A and b arguments as
A = [1 1;-1 1];
b = [1;0];
(I assume that your variable x is 2-D.) The other constraints should be represented by bounds:
lb = [0 0];
ub = [Inf 1/2];
So you should not use that constraint function at all.
As to why you are getting your current error, I don't know. I suggest that you evaluate the following and see if it leads to an error:
[ctest,ceqtest] = constraint(x0)
where x0 is the same value you use in your fmincon call.
Alan Weiss
MATLAB mathematical toolbox documentation

  0 件のコメント

サインイン to comment.



Translated by