How to get from a set of initial conditions, to a set of repeatable while loop functions.

1 view (last 30 days)
Several questions in one here!
I am trying to write a lap simulator. I have a series of equations that needed to be processed to get a range of initial conditions (initial speed etc). I now need to iterate the same series of equations in time steps of 0.001s in order to get constantly updating values (as the vehicle travels down a straight). How do i get a loop to read these initial values, but then create itself a log of the constantly updating values to use for the next iteration?
I am using a while loop (probably with incorrect coding grammar) as a repeat loop would be perfect, but is unavailiable.
This is where I am;
while true
if Vn > Gear4max
TractiveForce = TracForce5;
elseif Vn > Gear3max
TractiveForce = TracForce4;
elseif Vn > Gear2max
TractiveForce = TracForce3;
elseif Vn > Gear1max
TractiveForce = TracForce2;
elseif Vn < Gear1min
TractiveForce = TracForce1;
end
if TractiveForce > (MuAcc*Downforce0*Mg)
An = ((MuAcc*(Mdistrear*Mg+Mdistrear*Downforce0-Drag0-RR))/Mg)*9.81;
elseif TractiveForce < (MuAcc*Downforce0*Mg)
An = ((TractiveForce-Drag0-RR)/Mg)*9.81;
end
Vn = Vn+(An*Tstep);
Sn = Sn +(Vn*Tstep)+(0.5*An*Tstep^2);
Tn = Tn + Tstep;
Downforcen = CLA*Vn^2;
Dragn = CDA*Vn^2;
if Sn > 500
break;
end
end
Secondly, how can I put an upper limit on the value of Vn, for example. It is limited through gearing to a certain speed, how can I make it recognize that?
Thank you for all help :)

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!