how to pass nonlinear nested constraints in patternsearch?
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hi I have used patternsearch for minimizing a four-parameter nonlinear constraint function(J(x)). My program is:
%%aa, bb, t, A are inputs and are n×1 matrices
J=@(x)0;
for i=1:length(aa)
j=2;
S=@(x)(1/x(1))*(1-exp(-t(i)/x(2)));
while j<=i
S=@(x)S(x)-(exp(-t(i)/x(2))/(x(2)*x(3)))*(((aa(j)+aa(j-1)+x(4)*bb(j))*exp(t(j)/x(2))*(0.5*(t(j)-t(j-1))));
j=j+1;
end
R=@(x)(S(x)^(-1))-A(i);
J=@(x)J(x)+R(x);
c{i}=@(x)R(x)-0.001;
i=i+1;
end
A=[0 -1 0 1];
b=0;
Aeq=[];
beq=[];
lb=[0 0 0 0];
ub=[1 inf inf inf];
x0=[1 2 3 4];
opts=optimset('MaxFunEval',1e8,'TolFun',1e-3,'MaxIter',5000);
[x,fval,exitflag,output]=patternsearch(J,x0,A,b,Aeq,beq,lb,ub,c,opts)
When I run it without constraints, it works well but by considering the constraints an error ‘Error using @(x)R(x)-0.001.Too many input arguments… Caused by: Failure in initial user-supplied nonlinear constraint function evaluation. PATTERNSEARCH cannot continue.’ occurs. I guess it is because my constrains are nested functions and the algorithm considers the R(x) as an argument. Can anybody help me to eliminate this problem?
댓글 수: 2
Alan Weiss
2014년 12월 2일
Please format your code using the {}Code button. Then we might have a chance to read it.
Alan Weiss
MATLAB mathematical toolbox documentation
Effat
2014년 12월 2일
답변 (1개)
Alan Weiss
2014년 12월 3일
0 개 추천
Not only do I find your coding mysterious, but I am pretty sure that it doesn't do what you think it does. I suggest that you step through the code using the debugger to see what it is doing.
As for your question, it seems that your nonlinear constraint is wrong in two ways:
- Nonlinear constraint functions must return two outputs, c and ceq. Just calling yours c does not exempt your function from returning two outputs. If you don't have ceq, then set ceq to [].
- Your c seems to return a cell array. If that is correct, then that is not the correct form of a nonlinear constraint function. Instead, c must return a real vector. And, of course, it must return ceq as well.
Alan Weiss
MATLAB mathematical toolbox documentation
댓글 수: 2
Effat
2014년 12월 4일
Alan Weiss
2014년 12월 5일
Is your c function returning a cell array or a vector? If it returns a cell array, then that is your problem. Once more, I suggest that you use the debugger to see what happens as your code runs.
Alan Weiss
MATLAB mathematical toolbox documentation
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!