loop to quit based on rate of change
i’m trying to get this while loop to quite based on the rate of change of v being less than .05%.
the while loop quits now just based on t(i)<7; but i’m trying to figure out how i can get this loop to stop based on ((v(2)-v(1))/(t(2)-t(1))<= 0.05.
clc
clear
m = 36/1000;
g=9.81;
T=5;
A=.00044316;
Cd=0.75;
rho=1.203;
a(1)=0;
v(1)=0;
h(1)=0;
t(1)=0;
t_step=0.001;
i=1;
u(1)=0;
while t(i)<7;
a(i+1)= ((T)-(m*g)-(0.5*rho*A*Cd*v(i)^2))/m;
v(i+1)= a(i+1)*t_step+v(i);
h(i+1)= v(i+1)*t_step+h(i);
t(i+1)=t(i)+t_step;
i=i+1;
end
plot(t,v)i’m trying to get this while loop to quite based on the rate of change of v being less than .05%.
the while loop quits now just based on t(i)<7; but i’m trying to figure out how i can get this loop to stop based on ((v(2)-v(1))/(t(2)-t(1))<= 0.05.
clc
clear
m = 36/1000;
g=9.81;
T=5;
A=.00044316;
Cd=0.75;
rho=1.203;
a(1)=0;
v(1)=0;
h(1)=0;
t(1)=0;
t_step=0.001;
i=1;
u(1)=0;
while t(i)<7;
a(i+1)= ((T)-(m*g)-(0.5*rho*A*Cd*v(i)^2))/m;
v(i+1)= a(i+1)*t_step+v(i);
h(i+1)= v(i+1)*t_step+h(i);
t(i+1)=t(i)+t_step;
i=i+1;
end
plot(t,v) i’m trying to get this while loop to quite based on the rate of change of v being less than .05%.
the while loop quits now just based on t(i)<7; but i’m trying to figure out how i can get this loop to stop based on ((v(2)-v(1))/(t(2)-t(1))<= 0.05.
clc
clear
m = 36/1000;
g=9.81;
T=5;
A=.00044316;
Cd=0.75;
rho=1.203;
a(1)=0;
v(1)=0;
h(1)=0;
t(1)=0;
t_step=0.001;
i=1;
u(1)=0;
while t(i)<7;
a(i+1)= ((T)-(m*g)-(0.5*rho*A*Cd*v(i)^2))/m;
v(i+1)= a(i+1)*t_step+v(i);
h(i+1)= v(i+1)*t_step+h(i);
t(i+1)=t(i)+t_step;
i=i+1;
end
plot(t,v) loop MATLAB Answers — New Questions