Indexing in a while loop
Show older comments
I need the results to be the length until mfuel is equal to or less than 0. Please help.
time(i)=0;
dt=0.01; % change in time
height(i)=1;% elevation
i=1;
BR=4.8; % burn rate
mfuel(i)=134; % mass fuel
mtot=150; % total mass
mcase=16; % mass of casing
fthrust(i)=1560; % force of thruse
athrust(i)=0; % thrust acceleration
ag=-9.81; % acceleration of gravity
atot(i)=athrust(i)-ag; % total acceleration
v(i)=0; % velocity
ke(i)=0; % kinetic energy
pe(i)=0; % potential energy
te(i)=0; % total energy
while height > 0
time(i+1)=time(i)+dt;
mfuel(i+1)=max((mfuel(i)-BR*dt),0); % add if statement to make sure mfuel isnt <0
mtot(i+1)=mfuel(i+1)+mcase;
fthrust(i+1)=1560*sign(mfuel(i+1)); % -1 if neg 0 if zero 1 is pos
athrust(i+1)=fthrust(i+1)/mtot(i+1);
v(i+1)=v(i)+((atot(i+1)+atot(i))/2)*dt;
height(i+1)=height(i)+((v(i+1)+v(i))/2)*dt;
ke(i+1)=1/2*mtot(i)*v(i)^2;
pe(i+1)=mtot(i)*(-g)*height(i);
te(i+1)=pe(i)+ke(i);
end
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!