How to store values from all iterations into one vector?
6 次查看(过去 30 天)
显示 更早的评论
Hi, I am trying to run my code to calculate values over every iteration and them plot my V value vs time, however, I haven't been able to successfully store all of the calculated values over all the iterations. I tried to with the brackets before the for loop but I don't think I did them correctly. Any help in figuring out how to do this would be appreciated. Thank you!
function RocketLaunch
clc, clear
m_rocket = 24675.42; % Empty Mass / Mass of Rocket [kg]
m_fuel0= 379838.25; % Mass of Fuel [kg]
m_total0 = m_fuel0 + m_rocket; % Initial Total Mass
thrust0 = 0; % Initial Thrust
thrust = 8296425.89; % Thrust in Newtons - Assuming to be constant
BurnTime = 161; % Burn Time [s]
m_dot = m_fuel0./BurnTime; % Mass flow rate of fuel - Assuming it is constant
t = [1:155]; % Code only works to t = 155s
VEL = [];
EX_VEL = [];
for i = 1:length(t-1)
if i > BurnTime
m_fuel0 = 0;
thrust = 0;
m_dot = 0;
V_e = thrust./m_dot;
V = V_e.*log(m_total./m_rocket);
end
m_fuel = m_fuel0-m_dot.*i;
BurnRate = (m_fuel - m_rocket)./BurnTime;
m_total = (m_fuel + m_rocket)+(BurnRate.*i);
V_e = thrust./m_dot;
V = V_e.*log(m_total./m_rocket);
end
VEL(i) = V
EX_VEL(i) = V_e
plot(t,VEL)
0 个评论
采纳的回答
KSSV
2018-7-25
function RocketLaunch
clc, clear
m_rocket = 24675.42; % Empty Mass / Mass of Rocket [kg]
m_fuel0= 379838.25; % Mass of Fuel [kg]
m_total0 = m_fuel0 + m_rocket; % Initial Total Mass
thrust0 = 0; % Initial Thrust
thrust = 8296425.89; % Thrust in Newtons - Assuming to be constant
BurnTime = 161; % Burn Time [s]
m_dot = m_fuel0./BurnTime; % Mass flow rate of fuel - Assuming it is constant
t = [1:155]; % Code only works to t = 155s
VEL = zeros([],1);
EX_VEL = zeros([],1);
for i = 1:length(t-1)
if i > BurnTime
m_fuel0 = 0;
thrust = 0;
m_dot = 0;
V_e = thrust./m_dot;
V = V_e.*log(m_total./m_rocket);
end
m_fuel = m_fuel0-m_dot.*i;
BurnRate = (m_fuel - m_rocket)./BurnTime;
m_total = (m_fuel + m_rocket)+(BurnRate.*i);
V_e = thrust./m_dot;
V = V_e.*log(m_total./m_rocket);
VEL(i) = V ;
EX_VEL(i) = V_e ;
end
plot(t,VEL)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle & Nuclear Physics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!