67 ビュー (過去 30 日間)
Chukwunememma Uponi 2019 年 12 月 3 日
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);
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);
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]')

サインインしてコメントする。

### 採用された回答

Raj 2019 年 12 月 3 日
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')
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 件のコメント表示非表示 2 件の古いコメント
Chukwunememma Uponi 2019 年 12 月 6 日
This was so helpful! Thank you!

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by