Filter löschen
Filter löschen

How to fix: "Index exceeds matrix dimension"

2 Ansichten (letzte 30 Tage)
Sanzhar Januzakov
Sanzhar Januzakov am 16 Feb. 2018
Bearbeitet: Shounak Shastri am 16 Feb. 2018
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

Akzeptierte Antwort

Shounak Shastri
Shounak Shastri am 16 Feb. 2018
Bearbeitet: Shounak Shastri am 16 Feb. 2018
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.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by