フィルターのクリア

How Can i transform condition into constraint equation?

2 ビュー (過去 30 日間)
Maria
Maria 2023 年 1 月 10 日
コメント済み: Walter Roberson 2023 年 1 月 17 日
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 Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by