Filter löschen
Filter löschen

How to store values from all iterations into one vector?

4 Ansichten (letzte 30 Tage)
Alison Michell
Alison Michell am 25 Jul. 2018
Kommentiert: Alison Michell am 25 Jul. 2018
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)

Akzeptierte Antwort

KSSV
KSSV am 25 Jul. 2018
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)

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by