Index exceeds the number of array elements. Index must not exceed 1.
1 view (last 30 days)
Show older comments
Please help to resolve error. Below is my code.
% value of constants
a1 = 0.1;
omega1 = 2;
G = 0.01;
C12 = 0.001;
C13 = 0.006;
C14 = 0.008;
C15 = 0.0010;
C16 = 0.0012;
C17 = 0.0014;
C18 = 0.0016;
C19 = 0.0018;
C110 = 0.0020;
C111 = 0.0022;
C112 = 0.002;
C113 = 0.003;
C114 = 0.005;
C115 = 0.007;
C116 = 0.009;
C117 = 0.0011;
C118 = 0.0013;
C119 = 0.0015;
C120 = 0.0017;
C121 = 0.0019;
C122 = 0.0021;
C123 = 0.0023;
dt = 0.01; % step size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x1(1) = 0.5;
y1(1) = 0.5;
x2(1) = 0.5;
y2(1) = 0.5;
x3(1) = 0.5;
y3(1) = 0.5;
x4(1) = 0.5;
y4(1) = 0.5;
x5(1) = 0.5;
y5(1) = 0.5;
x6(1) = 0.5;
y6(1) = 0.5;
x7(1) = 0.5;
y7(1) = 0.5;
x8(1) = 0.5;
y8(1) = 0.5;
x9(1) = 0.5;
y9(1) = 0.5;
x10(1) = 0.5;
y10(1) = 0.5;
x11(1) = 0.5;
y11(1) = 0.5;
x12(1) = 0.5;
y12(1) = 0.5;
x13(1) = 0.5;
y13(1) = 0.5;
x14(1) = 0.5;
y14(1) = 0.5;
x15(1) = 0.5;
y15(1) = 0.5;
x16(1) = 0.5;
y16(1) = 0.5;
x17(1) = 0.5;
y17(1) = 0.5;
x18(1) = 0.5;
y18(1) = 0.5;
x19(1) = 0.5;
y19(1) = 0.5;
x20(1) = 0.5;
y20(1) = 0.5;
x21(1) = 0.5;
y21(1) = 0.5;
x22(1) = 0.5;
y22(1) = 0.5;
x23(1) = 0.5;
y23(1) = 0.5;
for i = 2:2000
x1(i) = x1(i-1) + ( ( a1 - x1(i-1)^2 - y1(i-1)^2 )*x1(i-1) - omega1*y1(i-1) + G*C12*( x2(i-1) - x1(i-1) ) + G*C13*( x3(i-1) - x1(i-1) ) + G*C14*( x4(i-1) - x1(i-1) ) ) + G*C15*( x5(i-1) - x1(i-1) ) + G*C16*( x6(i-1) - x1(i-1) ) + G*C17*( x7(i-1) - x1(i-1) ) + G*C18*( x8(i-1) - x1(i-1) ) + G*C19*( x9(i-1) - x1(i-1) ) + G*C110*( x10(i-1) - x1(i-1) ) + G*C111*( x11(i-1) - x1(i-1) ) + G*C112*( x12(i-1) - x1(i-1) ) + G*C113*( x13(i-1) - x1(i-1) ) + G*C114*( x14(i-1) - x1(i-1) ) + G*C115*( x15(i-1) - x1(i-1) ) + G*C116*( x16(i-1) - x1(i-1) ) + G*C117*( x17(i-1) - x1(i-1) ) + G*C118*( x18(i-1) - x1(i-1) ) + G*C119*( x19(i-1) - x1(i-1) ) + G*C120*( x20(i-1) - x1(i-1) ) + G*C121*( x21(i-1) - x1(i-1) ) + G*C122*( x22(i-1) - x1(i-1) ) + G*C123*( x23(i-1) - x1(i-1) ) *dt;
y1(i) = y1(i-1) + ( ( a1 - x1(i-1)^2 - y1(i-1)^2 )*y1(i-1) + omega1*x1(i-1) + G*C12*( y2(i-1) - y1(i-1) ) + G*C13*( y3(i-1) - y1(i-1) ) + G*C14*( y4(i-1) - y1(i-1) ) ) + G*C15*( y5(i-1) - y1(i-1) ) + G*C16*( y6(i-1) - y1(i-1) ) + G*C17*( y7(i-1) - y1(i-1) ) + G*C18*( y8(i-1) - y1(i-1) ) + G*C19*( y9(i-1) - y1(i-1) ) + G*C110*( y10(i-1) - y1(i-1) ) + G*C111*( y11(i-1) - y1(i-1) ) + G*C112*( y12(i-1) - y1(i-1) ) + G*C113*( y13(i-1) - y1(i-1) ) + G*C114*( y14(i-1) - y1(i-1) ) + G*C115*( y15(i-1) - y1(i-1) ) + G*C116*( y16(i-1) - y1(i-1) ) + G*C117*( y17(i-1) - y1(i-1) ) + G*C118*( y18(i-1) - y1(i-1) ) + G*C119*( y19(i-1) - y1(i-1) ) + G*C120*( y20(i-1) - y1(i-1) ) + G*C121*( y21(i-1) - y1(i-1) ) + G*C122*( y22(i-1) - y1(i-1) ) + G*C123*( y23(i-1) - y1(i-1) ) *dt;
end
figure
hold on
plot(x1)
1 Comment
Cameron
on 29 Dec 2022
You have no value for x2(2), x3(2), x4(2), etc. so when i = 3 and your code looks for x2(i-1), there is no value there and gives you the error you're seeing.
Answers (0)
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!