Unable to convert expression into double array, in Gamultiobj
조회 수: 1 (최근 30일)
이전 댓글 표시
Greetings, I need some help with figuring out how to make functions for optimization tools which accept symbolic handles (or so I think). I been trying with many solutions in this community but none seem to fit my problem. Most, if not all revolve around functions with limited symbolic variables that are not dynamic.
My problem is that I have 2 objective linear vectors Z_1 and Z_2 which can have many variables (from 82 to 1k or more), and trying to use the gamultiobj tool, I have the matrices and their vectors, the only thing that I can't figure out is how to make the fit function work. Here is the relevant code:
yy=sym([]); % I start with making the fit function as symbolic as suggested by many other solutions.
yy(:,1)=Z_1*sym('x',[1,size(Z_1,2)])'; % I try to vectorize the fitness function for Z_1 (which I think here is the problem) making the variables 'x1',..., 'xn'
yy(:,2)=Z_2*sym('x',[1,size(Z_1,2)])'; % And Z_2
[x,fval]=gamultiobj(@(x)yy,size(Z_1,2),MatrixInequality,VectorInequality,MatrixEquality,VectorEquality)
I think the problem is the vectorized fit function which may seem easy to fix if you are making only 3 or 8 or so variables (by hand) but if it's very dynamic, how can I make it work?
I attached the Z_1, Z_1 vectors as well as the matrices with their vectors if you need to take a closer look.
댓글 수: 0
채택된 답변
Walter Roberson
2021년 12월 1일
Use matlabFunction() to convert yy to a numeric function. Be sure to use the 'vars' option to bundle all of the inputs into a single row vector
댓글 수: 4
Walter Roberson
2021년 12월 2일
You might want to experiment with increasing your population size using the gamultiobj options.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!