How can I resolve this 'Improper assignment with rectangular..' error while using Genetic Algorithm minimization (ga function)?

조회 수: 2 (최근 30일)
I am getting an error while using the ga() function with ub,lb,non-linear and integer constraints but no linear inequality/equality constraints.
The error is- "Improper assignment with rectangular empty matrix."
Here's the piece of my code- (EWPL and constraint are my functions which accept a single argument i.e. y. constraint returns C and Ceq=[])
%SETTING THE INTEGER CONSTRAINTS ON ALL DECISION VARIABLES EXCEPT FOR y(1).
for i=2:nvars
intcon(i-1)=i;
end
%RESULT
f=@(y)EWPL(y);
nonlcon=@(y)constraint(y);
yopt=ga(f,nvars,[],[],[],[],lb,ub,nonlcon,intcon);
Interestingly, the error is totally different when I try to run the code some times. The error is in line 351 of ga() again but it's different.
Can anyone please tell me where I am going wrong? This is the very first time that I am using the genetic algorithm. Thanks :)

채택된 답변

Matt J
Matt J 2015년 10월 23일
The "user-supplied nonlinear constraint function" mentioned in the error message is your nonlcon function. Basically, constraint() is returning output that is bad in some way. You will probably have to use the debugger to trap this.
  댓글 수: 1
Aakash Rajwani
Aakash Rajwani 2015년 10월 24일
Yes, that was really the problem. It was inside the constraint function. It is a Chemical Engineering problem and as always, the part creating all the problems was the units of the quantities. Debugging it right now.
Thank you so very much for the help and time, Matt. I really appreciate it :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Alan Weiss
Alan Weiss 2015년 10월 23일
There could be several problems here. One is that you set intcon wrong. If you want all variables except for the first to be integer-valued, then
intcon = 2:nvars;
Another could be your nonlinear constraint function. Does it return two values, c and ceq? And is ceq = []? It should be.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 1
Aakash Rajwani
Aakash Rajwani 2015년 10월 24일
Yes, it returns two values. There were some bad values (NaN) being returned in C in the constraint function. I am debugging it right now. Thank you so much for your help :) I appreciate it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Genetic Algorithm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by