Rocket Engine Thrust, Code Running Infinitely [Homework]

16 visualizaciones (últimos 30 días)
Natalie Spalding
Natalie Spalding el 8 de Mzo. de 2021
Comentada: Walter Roberson el 8 de Mzo. de 2021
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 comentario
Walter Roberson
Walter Roberson el 8 de Mzo. de 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
t = 3.5973
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
h = 160.1696
% 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

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by