Conversion to double from optim.prob​lemdef.Opt​imizationE​xpression is not possible

1 view (last 30 days)
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.

Answers (1)

Walter Roberson
Walter Roberson on 25 Mar 2023
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

Community Treasure Hunt

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

Start Hunting!