Conversion to double from optim.problemdef.OptimizationExpression is not possible
1 次查看(过去 30 天)
显示 更早的评论
Hello
I have an optimization problem and I have a constraint function in it, but I get error ' Conversion to double from optim.problemdef.OptimizationExpression is not possible' in below code in line 16:
function constraints = constraintFcn_2(v)
global Q
t=0.1;
x1=[6 3 0]';
x2=[3 5 0]';
x3=[1 4 0]';
x4=[1 2 0]';
x5=[3 1 0]';
M=[x1';x2';x3';x4';x5'];
coeff1= pca(M);
direc1=coeff1(:,1);
K=[];
W = Q;
TT=W+v;
for i=1:length(TT)/3
K(i,1)=TT(3*i-2); %%%%%%%Error occurs in this line
K(i,2)=TT(3*i-1);
K(i,3)=TT(3*i);
end
coeffpca=pca(p_mds_pca);
direction=coeffpca(:,1);
%%%%%%%%%%%%%%%%%%55
constraints=norm(direction-direc1)<=t;
end
How can I fix it?
thank you.
0 个评论
回答(1 个)
Walter Roberson
2023-3-25
https://www.mathworks.com/help/optim/ug/fcn2optimexpr.html#mw_7959222a-434e-46eb-aec3-fe7942326891
I am not sure if you will need remove the inequality from the function; the example shows the comparison after the call
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Nonlinear Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!