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

3 views (last 30 days)
Beginner coder here. I'm trying to run my code and I've got an index error. I don't know how to fix it. I have a bunch of variables assigned to number values, so I left those out, but I know my error is stemming from this loop. Again, I don't know how to fix it.
Any help would be greatly appreiciated
for i=2:nx
error=1;
x=x+delta_x;
delta2_old = delta2(i-1);
while error > epsilon
alpha = (3/10) - (lambda/120);
beta = (37/315) - (lambda/945) - ((lambda^2)/9072);
gamma = 2 + (lambda/6);
u0 = (h1*U) / (h1 - ((x*(h1-h2))/L) - ((alpha*delta2_old)/beta));
delta2_new = sqrt( ((d2^2) + (2*v*(beta*gamma)/u0)*delta_x) / (1 + (2*(2 + (alpha/beta))) * ((u0 - u_0)/u0)) );
error = abs((delta2_new - delta2_old)/delta2_new);
u0_old = u0_new;
delta2_old = delta2_new;
end
delta2(i)= delta2_new;
delta1(i)= (alpha*delta2(i))/beta;
tau(i)= beta*gamma*((mu*u0(i))/delta2(i));
xv(i)=x;
iv(i)=i;
end

Accepted Answer

Torsten
Torsten on 13 Apr 2022
tau(i)= beta*gamma*((mu*u0)/delta2(i));
instead of
tau(i)= beta*gamma*((mu*u0(i))/delta2(i));

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!