Rocket Engine Thrust, Code Running Infinitely [Homework]
조회 수: 16 (최근 30일)
이전 댓글 표시
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
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
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
