Please help: How to do a time step?

31 visualizaciones (últimos 30 días)
Chukwunememma Uponi
Chukwunememma Uponi el 3 de Dic. de 2019
Comentada: Chukwunememma Uponi el 6 de Dic. de 2019
Here is my code, i need the final velocity from u_1 to be the initial velocity for u_2. How do i do this please?
close all
clc;
%define variables
mi_1=2290000;
mf_1=130000;
tb_1=165;
Isp_1=263;
mi_2=496200;
mf_2=40100;
tb_2=360;
Isp_2=421;
mi_3=123000;
mf_3=13500;
tb_3=500;
Isp_3=421;
g=9.81; %acceleration due to gravity
%stage 1
t_1=linspace(0,165);
mr_1=mi_1-((mi_1-mf_1)*(t_1/tb_1));
u_1=g.*(Isp_1.*log(mi_1./mr_1)-t_1); %velocity function
a_1=gradient(u_1, t_1(2)-t_1(1)); %differentiation of velocity function to get acceleration
p_1= cumtrapz(t_1,u_1); %integration of velocity function to get position
%end of stage 1
%stage 2
t_2=linspace(165,525);
mr_2=mi_2-((mi_2-mf_2)*(t_2/tb_2));
u_2=g.*(Isp_2.*log(mi_2./mr_2)-t_2);
a_2=gradient(u_2, t_2(2)-t_2(1));
p_2= cumtrapz(t_2,u_2);
%end of stage 2
%stage 3
t_3=linspace(525,1025);
mr_3=mi_3-((mi_3-mf_3)*(t_3/tb_3));
u_3=g.*(Isp_3.*log(mi_3./mr_3)-t_3);
a_3=gradient(u_3, t_3(2)-t_3(1));
p_3= cumtrapz(t_3,u_3);
%end of stage 3
%position-time graph
figure
plot(t_1,p_1,'blue',t_2,p_2,'blue',t_3,p_3,'blue')
title('Position')
ylabel('height[m]')
xlabel('time[s]')
%velocity-time graph
figure
plot(t_1,u_1,'red',t_2,u_2,'red',t_3,u_3,'red')
title('Velocity')
ylabel('Velocity[m/s]')
xlabel('time[s]')
%acceleration-time graph
figure
plot(t_1,a_1,'green',t_2,a_2,'green',t_3,a_3,'green')
title('Acceleration')
ylabel('Acceleration[m/s^2]')
xlabel('time[s]')

Respuesta aceptada

Raj
Raj el 3 de Dic. de 2019
The easiest way here would be:
1) Compute u_1 and u2 as you have done already.
2) Just take the last value of u_1 and append it as first value of u_2.
3) Plot accordingly.
So after computation of u_1 and u_2, you can use this:
u_2=[u_1(1,100) u_2]
t_2=[t_1(1,100) t_2]
And your plot command will be same as what you have now:
plot(t_1,u_1,'red',t_2,u_2,'red')
Capture.JPG
Update the code for other parameters on similar lines. Hope this is what you are looking for. Get back in case you get stuck somewhere!
  3 comentarios
Raj
Raj el 3 de Dic. de 2019
The logic works irrespective of variable. The code should look like this:
close all
clc;
%define variables
mi_1=2290000;
mf_1=130000;
tb_1=165;
Isp_1=263;
mi_2=496200;
mf_2=40100;
tb_2=360;
Isp_2=421;
mi_3=123000;
mf_3=13500;
tb_3=500;
Isp_3=421;
g=9.81; %acceleration due to gravity
%stage 1
t_1=linspace(0,165);
mr_1=mi_1-((mi_1-mf_1)*(t_1/tb_1));
u_1=g.*(Isp_1.*log(mi_1./mr_1)-t_1); %velocity function
a_1=gradient(u_1, t_1(2)-t_1(1)); %differentiation of velocity function to get acceleration
p_1= cumtrapz(t_1,u_1); %integration of velocity function to get position
%end of stage 1
%stage 2
t_2=linspace(165,525);
mr_2=mi_2-((mi_2-mf_2)*(t_2/tb_2));
u_2=g.*(Isp_2.*log(mi_2./mr_2)-t_2);
a_2=gradient(u_2, t_2(2)-t_2(1));
p_2= cumtrapz(t_2,u_2);
u_2=[u_1(1,100) u_2]
a_2=[a_1(1,100) a_2]
p_2=[p_1(1,100) p_2]
t_2=[t_1(1,100) t_2]
%end of stage 2
%stage 3
t_3=linspace(525,1025);
mr_3=mi_3-((mi_3-mf_3)*(t_3/tb_3));
u_3=g.*(Isp_3.*log(mi_3./mr_3)-t_3);
a_3=gradient(u_3, t_3(2)-t_3(1));
p_3= cumtrapz(t_3,u_3);
u_3=[u_2(1,101) u_3]
a_3=[a_2(1,101) a_3]
p_3=[p_2(1,101) p_3]
t_3=[t_2(1,101) t_3]
%end of stage 3
%position-time graph
figure
plot(t_1,p_1,'blue',t_2,p_2,'blue',t_3,p_3,'blue')
title('Position')
ylabel('height[m]')
xlabel('time[s]')
%velocity-time graph
figure
plot(t_1,u_1,'red',t_2,u_2,'red',t_3,u_3,'red')
title('Velocity')
ylabel('Velocity[m/s]')
xlabel('time[s]')
%acceleration-time graph
figure
plot(t_1,a_1,'green',t_2,a_2,'green',t_3,a_3,'green')
title('Acceleration')
ylabel('Acceleration[m/s^2]')
xlabel('time[s]')
Pos.JPG
vel.JPG
acc.JPG
Chukwunememma Uponi
Chukwunememma Uponi el 6 de Dic. de 2019
This was so helpful! Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by