Rocket Engine Thrust, Code Running Infinitely [Homework]

16 ビュー (過去 30 日間)
Natalie Spalding
Natalie Spalding 2021 年 3 月 8 日
コメント済み: Walter Roberson 2021 年 3 月 8 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 3 月 8 日
%% 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

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by