How to store values from all iterations into one vector?

5 ビュー (過去 30 日間)
Alison Michell
Alison Michell 2018 年 7 月 25 日
コメント済み: Alison Michell 2018 年 7 月 25 日
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)

採用された回答

KSSV
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)
  1 件のコメント
Alison Michell
Alison Michell 2018 年 7 月 25 日
Thank you so much!! That worked perfectly.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by