필터 지우기
필터 지우기

help with for loop matrix size

조회 수: 1 (최근 30일)
kyle mikkola
kyle mikkola 2015년 10월 9일
편집: Stephen23 2015년 10월 9일
% Initial values
h(1) = 0;
rho(1)= po*M/(R*To);
t(1) = 0;
vy(1) = 0;
dt = 1;
p(1) = po;
T(1) = To;
x(1) = 0;
vx(1) = 0;
Fdy(1)= 0;
Fdx(1)= 0;
% Position for loop
for i=1:480
m1(i) = ms + mt + ml*(1-t(i)/Tt) + mr + ms*(1-t(i)/Tb); % Mass Stage 1
g(i) = go * (re/(re+h(i)))^2; % Gravitational Acceleration Above Earth
Fdy(i) = .5 * rho(i) * vy(i)^2 * Cd *A; % Drag Force y-direction
rho(i) = (p(i) * M)/(R*T(i)); % Air Density
p(i) = po * (1-(L*h(i)/To))^(g(i)*M/(R*L)); % Air Pressure
T(i) = To - L * h(i); % Air Temperature
Fdx(i) = .5 * rho(i) * vx(i)^2 * Cd *A; % Drag Force x-direction
t(i+1)=t(i)+dt;
x(i+1)=x(i)+dt*(vx(i));
vx(i+1)=vx(i)+dt*(FTx1-Fdx(i))/m1(i);
h(i+1)=h(i)+dt*(vy(i));
vy(i+1)=vy(i)+dt*((FTy1/m1(i))+((vx(i)^2)/(re+h(i)))-g(i)-(Fdy(i)/m1(i)));
end
When I run this loop it says that rho(2) does not exist. It seems that the loop is not calculating a new value for rho every step. How should I fix this?
Thanks in advance
  댓글 수: 1
kyle mikkola
kyle mikkola 2015년 10월 9일
I thought that make rho(1)=something just means that i set the first rho value and then the loop would update every value after that? How should I change this?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2015년 10월 9일
You currently have
Fdy(i) = .5 * rho(i) * vy(i)^2 * Cd *A; % Drag Force y-direction
rho(i) = (p(i) * M)/(R*T(i)); % Air Density
You need to exchange those two lines so rho(i) is set before it is used.
  댓글 수: 1
kyle mikkola
kyle mikkola 2015년 10월 9일
Thank you so much! It works now!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Stalin Samuel
Stalin Samuel 2015년 10월 9일
In the line rho(1)= po*M/(R*To); you define that size of rho is 1.But you are accessing the values from 1 to 480.So it says that rho(2) does not exist.
  댓글 수: 1
Stalin Samuel
Stalin Samuel 2015년 10월 9일
편집: Walter Roberson 2015년 10월 9일
h = 0;
rho= po*M/(R*To);
t = 0;
vy= 0;
dt = 1;
p= po;
T= To;
x = 0;
vx= 0;
Fdy= 0;
Fdx= 0;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by