フィルターのクリア

How to fix: "Index exceeds matrix dimension"

2 ビュー (過去 30 日間)
Sanzhar Januzakov
Sanzhar Januzakov 2018 年 2 月 16 日
編集済み: Shounak Shastri 2018 年 2 月 16 日
Please help, trying to run while loop but it says that "Index exceeds matrix dimension" in "while(H(i)>Ha)". Guess I have a problem with increment and the size of Hs. Thank you in advance.
% Input Data
As = 5; % cross-sectional area of the spacecraft (m^2)
Ap = 150; % parachute area (m^2)
Hs = 150; % initial height (km)
U = 0; % initial velocity (m/s)
Hp = 3; % parachute deployment height (km)
Ha = 100; % height of the atmosphere above the earth (km)
M = 850; % mass of the spacecraft (kg)
C = 0.7; % drag coefficient
Tstep = 0.1; % time step (s)
% Increment initialisation
i=1; H(i)=Hs; v(i)=0; s(i)=0; t(i)=0;
%freefall without atmosphere
while(H(i)>Ha)
FD=0;
g(i) = (40*10^7)/(6371+H(i))^2;
a(i) = g(i); % As FD = 0
s(i+1)= U*Tstep + 0.5*a(i)*(Tstep^(2));
v(i+1)= U + a(i)*Tstep;
i=i+1; continue
end

採用された回答

Shounak Shastri
Shounak Shastri 2018 年 2 月 16 日
編集済み: Shounak Shastri 2018 年 2 月 16 日
You are not updating H(i+1) in your while loop.
"i=1; H(i)=Hs;"
This line creates an array named "H" of size [1, 1] which has one value "Hs". In your loop, you are not doing anything to the array which would increase the size of "H".
I don't know what you are trying to do with the code but I am guessing you might want to do
H(i+1) = H(i) - s(i)
This will increase the size of your array and the loop would run till H(i) > Hs.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by