Index exceeds the number of array elements. Index must not exceed 1.

10 vues (au cours des 30 derniers jours)
Victoria Rodriguez
Victoria Rodriguez le 21 Avr 2022
Modifié(e) : Jon le 21 Avr 2022
Error is occuring in my delta2_new variable, line 6 in this portion of my code. Unsure how to fix it and get my code running.
while error > epsilon
alpha = (3/10) - (lambda/120);
beta = (37/315) - (lambda/945) - ((lambda^2)/9072);
gamma = 2 + (lambda/6);
u0(i) = (h1*U) / (h1 - ((x*(h1-h2))/L) - ((alpha*delta2_old)/beta));
delta2_new = sqrt( ((d2(i-1)^2) + (2*v*(beta*gamma)/u0(i))*(delta_x)) / (1 + (2*(2 + (alpha/beta))) * ((u0(i) - u0(i-1))/u0(i))) );
tau(i) = (beta/gamma) * ((mu*u0(i)) / delta2_new);
delta = delta2_new / beta;
delta1(i) = alpha*beta;
error = abs((delta2_new - delta2_old)/delta2_new);
delta2_old = delta2_new;
end
  2 commentaires
Jon
Jon le 21 Avr 2022
Modifié(e) : Jon le 21 Avr 2022
It's hard to tell what is going on here with the subscripts. Can you please also provide the code where your variable i and other variables d2, u0, etc are assigned
Torsten
Torsten le 21 Avr 2022
Please post executable code. With this incomplete code, nothing can be said concerning your error.
And it would help if you explain in a few words what you are trying to do.

Connectez-vous pour commenter.

Réponses (1)

David Hill
David Hill le 21 Avr 2022
What is i?
delta2_new = sqrt( ((d2(i-1)^2) + (2*v*(beta*gamma)/u0(i))*(delta_x)) / (1 + (2*(2 + (alpha/beta))) * ((u0(i) - u0(i-1))/u0(i))) );
%you are indexing into a variable (i=2) that only has one element. Check
%the sizes of all your variables (u0, d2). u0 is likely your problem.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by