How Can i transform condition into constraint equation?

2 次查看(过去 30 天)
Hello everyone!
i'm asking if i can change a condition line command into equation in order to use it in my problem. The condition is related to trajectory of vehicle in segment line, so if it arrives at the last point of the segment , it will come back to the initial point and keep going back and forth until the time ends.
in my code i wrote the condition as follow :
qu(1) = 0; % qu the initial position of vehicule
speed = 50; % 50 is the speed of vehicule ( constant)
k = 1;
while k < length(qu)
xk = qu(k) + speed;
if xk > 10000 %10000 is the length of the segment
speed = -50;
elseif xk < 0
speed = 50;
else
k = k+1;
qu(k) = xk;
end
end
How can i transform this code into simple equation?
any help is appreciated!
  3 个评论
Walter Roberson
Walter Roberson 2023-1-11
I'm pretty sure they are using fixed timestep, and that the speed variable is distance per time step.
Maria
Maria 2023-1-11
@Torsten i want to add the condition of the length of segment, it means that : when new position = length of the segment , the new position should return at the previous position.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2023-1-10
length(qu) starts as 1, k starts at 1, 1 < 1 is false, so the loop body is never entered. Therefore the code can be reduced to just the first two lines.
  26 个评论
Torsten
Torsten 2023-1-17
Thus my question remains.
Is qu(1) a multiple of 20 ?
If no: How to deal with the case that the opposite wall is not exactly hit at a time instant t ?
Walter Roberson
Walter Roberson 2023-1-17
Are you wanting the model to reject certain proposed values of qu(1), to say "Ah, this set of proposed parameters does not lead to a feasible model, try a different set of parameters" ?
If so, if qu(1) is one of the model parameters, then set a lower bound on it of 0, and set an upper bound of (L-NumberOfTimeSteps*v) . [If (L-NumberOfTimeSteps*v) would be negative, then that implies the equations are impossible to satisfy]
But I don't think that is what you want. You want the direction to reverse when you hit L or 0 and you want to keep going. That is not a constraint and cannot be handled by upper/lower bounds or by linear inequalities or by nonlinear equalities.

请先登录,再进行评论。

类别

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