Rocket Engine Thrust, Code Running Infinitely [Homework]
13 views (last 30 days)
Show older comments
Hi!
Background:

Code:
%% Problem 1. Rocket
clear all
clc
a=1;
g=9.81;
% a.)
t=0;
while(1)
v=3.5*(1/a*t*exp(a*t)-(1/a^2)*exp(a*t)+1/a^2)-g*t;
if v>300,break,end
t=t+0.0001;
end
t
h=3.5*(1/a^2*t*exp(a*t)-2/a^3*exp(a*t)+2/a^3+1/a^2*t)-g*t^2/2
% b.)
alf=1:0.1:5;
t=zeros(1,length(alf));
for i=1:length(alf)
while (1)
v=3.5*(1/alf(i)*t(i)*exp(alf(i)*t(i)))-(1/alf(i)^2)*exp(alf(i)*t(i))+1/alf(i)^2-g*t % first should equal 3.5973
if v>300,break,end
t(i)=t(i)+0.0001;
end
end
It seems to just run on and on, and I'm not seeing where I screwed up this code.
1 Comment
Walter Roberson
on 8 Mar 2021
%% Problem 1. Rocket
a=1;
g=9.81;
% a.)
t=0;
while(1)
v=3.5*(1/a*t*exp(a*t)-(1/a^2)*exp(a*t)+1/a^2)-g*t;
if v>300,break,end
t=t+0.0001;
end
t
h=3.5*(1/a^2*t*exp(a*t)-2/a^3*exp(a*t)+2/a^3+1/a^2*t)-g*t^2/2
% b.)
alf=1:0.1:5;
nalf = length(alf);
t=zeros(1,nalf);
vrecord = zeros(1,nalf);
for i=1:nalf
while (1)
v=3.5*(1/alf(i)*t(i)*exp(alf(i)*t(i)))-(1/alf(i)^2)*exp(alf(i)*t(i))+1/alf(i)^2-g*t(i); % first should equal 3.5973
if v>300,break,end
t(i)=t(i)+0.0001;
end
vrecord(i) = v;
end
plot(t, vrecord); drawnow
Answers (0)
See Also
Categories
Find more on Startup and Shutdown 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!