I know a car's starting speed and deceleration rate. How can I calculate the stopping time in the code?

So I plotted a car's forward speed by time plot and I calculated it's deceleration rate by the plot. I know it stops at 74.967 seconds but I don't know how to implement and show it in this code. What should I add? Deceleration rate is 0.4 m/s^2. Should I write another code with these values or can I add it directly to this and if so how?
ti=0.0; tf=15.0; ui=30.0;
m=2585; g=10; W=m*g; Theta=0.0; Fx=0;
f=0.03; rho=1.225; Cd=0.2; A=2.9; uw=0.0;
tol=1.0E-4; trace=1;
options = odeset('RelTol',tol,'AbsTol',tol);
[t,u]= ode23(@(t,u)asdfg(t,u,m,Fx,W,Theta,f,rho,Cd,A,uw),[ti,tf],ui,options);
plot(t,u,"r")
title("Vehicle Forward Speed");
xlabel("Time(sec)")
ylabel("u(m/sec)"); grid;
function udot = asdfg(t,u,m,Fx,W,Theta,f,rho,Cd,A,uw)
if u>0
udot=(1/m)*(Fx-W*sin(Theta)-f*W*cos(Theta)-0.5*rho*Cd*A*(u+uw)^2);
else
udot=0;
end
end

 Accepted Answer

Well, your deceleration rate is not constant and what I see from the code it starts with -0.4237 m/s^2 and ends with -0.3 m/s^2, your vehicle will not stop at 75 sec. It would have if deceleration rate had been constant.
If you put tf to be 100 sec, you can see that it will stop around 89 sec
ti=0.0; tf=100.0; ui=30.0;
m=2585; g=10; W=m*g; Theta=0.0; Fx=0;
f=0.03; rho=1.225; Cd=0.2; A=2.9; uw=0.0;
tol=1.0E-4; trace=1;
options = odeset('RelTol',tol,'AbsTol',tol);
[t,u]= ode23(@(t,u)asdfg(t,u,m,Fx,W,Theta,f,rho,Cd,A,uw),[ti,tf],ui,options);
plot(t,u,"r")
title("Vehicle Forward Speed");
xlabel("Time(sec)")
ylabel("u(m/sec)"); grid;
tstop =t(find(u<=0, 1,'first'))
tstop = 88.9015
function udot = asdfg(t,u,m,Fx,W,Theta,f,rho,Cd,A,uw)
if u>0
udot=(1/m)*(Fx-W*sin(Theta)-f*W*cos(Theta)-0.5*rho*Cd*A*(u+uw)^2);
else
udot=0;
end
end

More Answers (0)

Categories

Products

Release

R2022b

Asked:

on 7 Nov 2022

Edited:

on 7 Nov 2022

Community Treasure Hunt

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

Start Hunting!