Effacer les filtres
Effacer les filtres

How to fix: "Index exceeds matrix dimension"

2 vues (au cours des 30 derniers jours)
Sanzhar Januzakov
Sanzhar Januzakov le 16 Fév 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

Réponse acceptée

Shounak Shastri
Shounak Shastri le 16 Fév 2018
Modifié(e) : Shounak Shastri le 16 Fév 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.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by