Borrar filtros
Borrar filtros

How Can i transform condition into constraint equation?

2 visualizaciones (últimos 30 días)
Maria
Maria el 10 de En. de 2023
Comentada: Walter Roberson el 17 de En. de 2023
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 comentarios
Walter Roberson
Walter Roberson el 11 de En. de 2023
I'm pretty sure they are using fixed timestep, and that the speed variable is distance per time step.
Maria
Maria el 11 de En. de 2023
@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.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 10 de En. de 2023
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 comentarios
Torsten
Torsten el 17 de En. de 2023
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 el 17 de En. de 2023
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by