How to solve "Conversion to logical from optim.prob​lemdef.Opt​imizationE​quality is not possible." ?

8 次查看(过去 30 天)
Hello!
Hi, I have meet the problem in MATLAB using problem based optimization, my optimization variable is q_int , i have used to generate a vector "qu", but an error displays
"Conversion to logical from optim.problemdef.OptimizationEquality is not possible.
Error in Generate_position (line 4)
if q_int == 0"
a = floor(L/UAV_Speed*dt);
q_int = optimvar("q_int","LowerBound",0,"UpperBound",a);
function [qu] = Generate_position(Flight_direction,q_int,UAV_Speed,dt,L)
direction = Flight_direction;
if q_int == 0 % here the error
direction = 1;
end
if q_int == L
direction = -1;
end
for k=2:T
qu(k) = qu(k-1) + direction*UAV_Speed*dt;
if qu(k)==0 || qu(k)==L
direction = -direction;
end
end
Appreciate for your help!
  8 个评论
Torsten
Torsten 2023-1-29
i initialize qu(1) = q_int*UAV_Speed*dt, but the same error is displayed,
I know. That's why I wrote: This will be another reason it will error.
Maria
Maria 2023-1-29
@Torsten the problem is when i change q_int with such value , it works. That's why i think that the problem in the initialization of my optimization variable q_int , but i see in documents that we wrote variables as shown, or there is something missing?
q_int = optimvar("q_int","LowerBound",0,"UpperBound",a);

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2023-1-29
编辑:Matt J 2023-1-29
This will solve the "Conversion to logical" error, but not all of the other issues raised by Torsten and me. In particular, Generate_position will still fail if q_int has any value other than 0 or L.
q_int = optimvar("q_int","LowerBound",0,"UpperBound",a);
fun=fcn2optimexpr(@(INPUT)computeThing(INPUT, T,Flight_direction,UAV_Speed,dt,L, N,T,BP,H,qc),...
q_int );
function arg1=computeThing(q_int, T,Flight_direction,UAV_Speed,dt,L, N,T,BP,H,qc)
qu = Generate_position(T,Flight_direction,q_int,UAV_Speed,dt,L);
arg1 = argument1(N,T,BP,H,qu,qc);
end
  122 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Programming and Mixed-Integer Linear Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by