Index exceeds the number of array elements. Index must not exceed 1.
    4 views (last 30 days)
  
       Show older comments
    
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 Comments
  Torsten
      
      
 on 21 Apr 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.
Answers (1)
  David Hill
      
      
 on 21 Apr 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.
0 Comments
See Also
Categories
				Find more on Matrix Indexing in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!