Azzera filtri
Azzera filtri

Loop until a condition is met

2 visualizzazioni (ultimi 30 giorni)
Jon Bilbao
Jon Bilbao il 20 Mar 2023
Commentato: Jon Bilbao il 21 Mar 2023
How can i do a function that give values for P0, P1, P2 and P3 until the condition Rt<Rmax is met
h=0.001;
Rmax=zeros(1,length(v));
t=zeros(1,length(v));
x=zeros(1,length(v));
for i=1:length(v)
t(i)=(v(i)-v(0))/a;
x(i)=v(0)*t(i)+(1/2)*a;
Rmax(i)=(v(i)^2)/amax;
end
B(x)=(1-x)^3*P0+3*x*(1-x)^2*P1+3*x^2*(1-x)*P2+t^3*P3;
Rt=(1+(diff(B)/h)^2)^(3/2)/(diff(B,2)/h);
end
  8 Commenti
Dyuman Joshi
Dyuman Joshi il 21 Mar 2023
Again, the for loop can be vectorized
l=0:0.1:Lt;
v=(v0.^2+2*a*l).^(1/2);
What are the inputs to the function VelTren? Please provide the values of v0, a, Lt and amax.
John, please note that when I say data, it means anything that is necessary to run the code, including definitions of variables and input values to functions.
This might be helpful to you, as that is the norm on this forum.
Jon Bilbao
Jon Bilbao il 21 Mar 2023
I didnt know that, thanks.
There are no stabliced because the purpose is to calculate the transition curve of any train, the idea is that introducing some values of v0, a Lt, R and L the prpgram will calculate the needed transition curve
a is the acceleration of the train it could be 1,5m/s^3
v0 is the speed that the trai has in the start of the curve tha could be 5m/s
Lt is the train longitude that could be 90m
L=the longitude of the curve 130m
R= Radius of the curve in the end of the transition curve, when the radius is constant
The purpose of the first code that i send is to claculate polynomical fuction (B(x)) in the transition curve, being Rt its radius, that make the de normal acceleration be less than 0,8 m/s^2.

Accedi per commentare.

Risposte (1)

Sachin
Sachin il 20 Mar 2023
I understand that you want to find values P0,P1,P2 and P3 until Rt<Rmax.
For this you can use while loop with condition Rt<Rmax;
while (Rt < Rmax)
% your code here
end

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by