Index exceeds the number of array elements. Index must not exceed 1.
2 次查看(过去 30 天)
显示 更早的评论
Please please help me to fix the error. I have tried changing the values for loop but its still not working. I don't know where I am making the mistake.
clear all; close all; clc;
% value of constants%
G = 1;
dt = 0.01; % step size
%Oscillator 1%
a1 = 0.1; omega1 = 1; C12 = 0.01; C13 = 0.024; C14 = 0.047; C15 = 0.070; C16 = 0.093; C17 = 0.0116; C18 = 0.0139; C19 = 0.0162; C110 = 0.0185; C111 = 0.0208; C112 = 0.0231; C113 = 0.0254; C114 = 0.0277; C115 = 0.0300; C116 = 0.0323; C117 = 0.0346; C118 = 0.0369; C119 = 0.0392; C120 = 0.0415; C121 = 0.0438; C122 = 0.0461; C123 = 0.0484;
%Oscillator 2%
a2 = 0.2; omega2 = 2; C21 = 0.02; C23 = 0.025; C24 = 0.048; C25 = 0.071; C26 = 0.094; C27 = 0.0117; C28 = 0.0140; C29 = 0.0163; C210 = 0.0186; C211 = 0.0209; C212 = 0.0232; C213 = 0.0255; C214 = 0.0278; C215 = 0.0301; C216 = 0.0324; C217 = 0.0347; C218 = 0.0370; C219 = 0.0393; C220 = 0.0416; C221 = 0.0439; C222 = 0.0462; C223 = 0.0485;
%Oscillator 3%
a3 = 0.3; omega3 = 3; C31 = 0.03; C32 = 0.026; C34 = 0.049; C35 = 0.072; C36 = 0.095; C37 = 0.0118; C38 = 0.0141; C39 = 0.0164; C310 = 0.0187; C311 =0.0210; C312 = 0.0233; C313 = 0.0256; C314 = 0.0279; C315 = 0.0302; C316 = 0.0325; C317 = 0.0348; C318 = 0.0371; C319 = 0.0394; C320 = 0.0417; C321 = 0.0440; C322 = 0.0463; C323 = 0.0486;
%Oscillator 4%
a4 = 0.4; omega4 = 4; C41 = 0.04; C42 = 0.027; C43 = 0.050; C45 = 0.073; C46 = 0.096; C47 = 0.0119; C48 = 0.0142; C49 = 0.0165; C410 = 0.0188; C411 =0.0211; C412 = 0.0234; C413 = 0.0257; C414 = 0.0280; C415 = 0.0303; C416 = 0.0326; C417 = 0.0349; C418 = 0.0372; C419 = 0.0395; C420 = 0.0418; C421 = 0.0441; C422 = 0.0464; C423 = 0.0487;
%Oscillator 5%
a5 = 0.5; omega5 = 5; C51 = 0.05; C52 = 0.028; C53 = 0.051; C54 = 0.074; C56 = 0.097; C57 = 0.0120; C58 = 0.0143; C59 = 0.0166; C510 = 0.0189; C511 =0.0212; C512 = 0.0235; C513 = 0.0258; C514 = 0.0281; C515 = 0.0304; C516 = 0.0327; C517 = 0.0350; C518 = 0.0373; C519 = 0.0396; C520 = 0.0419; C521 = 0.0442; C522 = 0.0465; C523 = 0.0488;
%Oscillator 6%
a6 = 0.6; omega6 = 6; C61 = 0.06; C62 = 0.029; C63 = 0.052; C64 = 0.075; C65 = 0.098; C67 = 0.0121; C68 = 0.0144; C69 = 0.0167; C610 = 0.0190; C611 = 0.0213; C612 = 0.0236; C613 = 0.0259; C614 = 0.0282; C615 = 0.0305; C616 = 0.0328; C617 = 0.0351; C618 = 0.0374; C619 = 0.0397; C620 = 0.0420; C621 = 0.0443; C622 = 0.0466; C623 = 0.0489;
%Oscillator 7%
a7 = 0.7; omega7 = 7; C71 = 0.07; C72 = 0.030; C73 = 0.053; C74 = 0.076; C75 = 0.099; C76 = 0.0122; C78 = 0.0145; C79 = 0.0168; C710 = 0.0191; C711 = 0.0214; C712 = 0.0237; C713 = 0.0260; C714 = 0.0283; C715 = 0.0306; C716 = 0.0329; C717 = 0.0352; C718 = 0.0375; C719 = 0.0398; C720 = 0.0421; C721 = 0.0444; C722 = 0.0467; C723 = 0.0490;
%Oscillator 8%
a8 = 0.8; omega8 = 8; C81 = 0.08; C82 = 0.031; C83 = 0.054; C84 = 0.077; C85 = 0.0100; C86 = 0.0123; C87 = 0.0146; C89 = 0.0169; C810 = 0.0192; C811 = 0.0215; C812 = 0.0238; C813 = 0.0261; C814 = 0.0284; C815 = 0.0307; C816 = 0.0330; C817 = 0.0353; C818 = 0.0376; C819 = 0.0399; C820 = 0.0422; C821 = 0.0445; C822 = 0.0468; C823 = 0.0491;
%Oscillator 9%
a9 = 0.9; omega9 = 9; C91 = 0.09; C92 = 0.032; C93 = 0.055; C94 = 0.078; C95 = 0.0101; C96 = 0.0124; C97 = 0.0147; C98 = 0.0170; C910 = 0.0193; C911 = 0.0216; C912 = 0.0239; C913 = 0.0262; C914 = 0.0285; C915 = 0.0308; C916 = 0.0331; C917 = 0.0354; C918 = 0.0377; C919 = 0.0400; C920 = 0.0423; C921 = 0.0446; C922 = 0.0469; C923 = 0.0492;
%Oscillator 10%
a10 = 0.10; omega10 = 10; C101 = 0.010; C102 = 0.033; C103 = 0.056; C104 = 0.079; C105 = 0.0102; C106 = 0.0125; C107 = 0.0148; C108 = 0.0171; C109 =0.0194 ; C1011 = 0.0217; C1012 = 0.0240; C1013 = 0.0263; C1014 = 0.0286; C1015 = 0.0309; C1016 = 0.0332; C1017 = 0.0355; C1018 = 0.0378; C1019 = 0.0401; C1020 = 0.0424; C1021 = 0.0447; C1022 = 0.0470; C1023 = 0.0493;
%Oscillator 11%
a11 = 0.11; omega11 = 11; C111 = 0.011; C112 = 0.034; C113 = 0.057; C114 = 0.080; C115 = 0.0103; C116 = 0.0126; C117 = 0.0149; C118 = 0.0172; C119 =0.0195 ; C1110 = 0.0218; C1112 = 0.0241; C1113 = 0.0264; C1114 = 0.0287; C1115 = 0.0310; C1116 = 0.0333; C1117 = 0.0356; C1118 = 0.0379; C1119 = 0.0402; C1120 = 0.0425; C1121 = 0.0448; C1122 = 0.0471; C1123 = 0.0494;
%Oscillator 12%
a12 = 0.12; omega12 = 12; C121 = 0.012; C122 = 0.035; C123 = 0.058; C124 = 0.081; C125 = 0.0104; C126 = 0.0127; C127 = 0.0150; C128 = 0.0173; C129 =0.0196 ; C1210 = 0.0219; C1211 = 0.0242; C1213 = 0.0265; C1214 = 0.0288; C1215 = 0.0311; C1216 = 0.0334; C1217 = 0.0357; C1218 = 0.0380; C1219 = 0.0403; C1220 = 0.0426; C1221 = 0.0449; C1222 = 0.0472; C1223 = 0.0495;
%Oscillator 13%
a13 = 0.13; omega13 = 13; C131 = 0.013; C132 = 0.036; C133 = 0.059; C134 = 0.082; C135 = 0.0105; C136 = 0.0128; C137 = 0.0151; C138 = 0.0174; C139 =0.0197 ; C1310 = 0.0220; C1311 = 0.0243; C1312 = 0.0266; C1314 = 0.0289; C1315 = 0.0312; C1316 = 0.0335; C1317 = 0.0358; C1318 = 0.0381; C1319 = 0.0404; C1320 = 0.0427; C1321 = 0.0450; C1322 = 0.0473; C1323 = 0.0496;
%Oscillator 14%
a14 = 0.14; omega14 = 14; C141 = 0.014; C142 = 0.037; C143 = 0.060; C144 = 0.083; C145 = 0.0106; C146 = 0.0129; C147 = 0.0152; C148 = 0.0175; C149 =0.0198 ; C1410 = 0.0221; C1411 = 0.0244; C1412 = 0.0267; C1413 = 0.0290; C1415 = 0.0313; C1416 = 0.0336; C1417 = 0.0359; C1418 = 0.0382; C1419 = 0.0405; C1420 = 0.0428; C1421 = 0.0451; C1422 = 0.0474; C1423 = 0.0497;
%Oscillator 15%
a15 = 0.15; omega15 = 15; C151 = 0.015; C152 = 0.038; C153 = 0.061; C154 = 0.084; C155 = 0.0107; C156 = 0.0130; C157 = 0.0153; C158 = 0.0176; C159 = 0.0199; C1510 = 0.0222; C1511 = 0.0245; C1512 = 0.0268; C1513 = 0.0291; C1514 = 0.0314; C1516 = 0.0337; C1517 = 0.0360; C1518 = 0.0383; C1519 = 0.0406; C1520 = 0.0429; C1521 = 0.0452; C1522 = 0.0475; C1523 = 0.0498;
%Oscillator 16%
a16 = 0.16; omega16 = 16; C161 = 0.016; C162 = 0.039; C163 = 0.062; C164 = 0.085; C165 = 0.0108; C166 = 0.0131; C167 = 0.0154; C168 = 0.0177; C169 = 0.0200; C1610 = 0.0223; C1611 = 0.0246; C1612 = 0.0269; C1613 = 0.0292; C1614 = 0.0315; C1615 = 0.0338; C1617 = 0.0361; C1618 = 0.0384; C1619 = 0.0407; C1620 = 0.0430; C1621 = 0.0453; C1622 = 0.0476; C1623 = 0.0499;
%Oscillator 17%
a17 = 0.17; omega17 = 17; C171 = 0.017; C172 = 0.040; C173 = 0.063; C174 = 0.086; C175 = 0.0109; C176 = 0.0132; C177 = 0.0155; C178 = 0.0178; C179 = 0.0201; C1710 = 0.0224; C1711 = 0.0247; C1712 = 0.0270; C1713 = 0.0293; C1714 = 0.0316; C1715 = 0.0339; C1716 = 0.0362; C1718 = 0.0385; C1719 = 0.0408; C1720 = 0.0431; C1721 = 0.0454; C1722 = 0.0477; C1723 = 0.0500;
%Oscillator 18%
a18 = 0.18; omega18 = 18; C181 = 0.018; C182 = 0.041; C183 = 0.064; C184 = 0.087; C185 = 0.0110; C186 = 0.0133; C187 = 0.0156; C188 = 0.0179; C189 = 0.0202; C1810 = 0.0225; C1811 = 0.0248; C1812 = 0.0271; C1813 = 0.0294; C1814 = 0.0317; C1815 = 0.0340; C1816 = 0.0363; C1817 = 0.0386; C1819 = 0.0409; C1820 = 0.0432; C1821 = 0.0455; C1822 = 0.0478; C1823 = 0.0501;
%Oscillator 19%
a19 = 0.19; omega19 = 19; C191 = 0.019; C192 = 0.042; C193 = 0.065; C194 = 0.088; C195 = 0.0111; C196 = 0.0134; C197 = 0.0157; C198 = 0.0180; C199 = 0.0203; C1910 = 0.0226; C1911 = 0.0249; C1912 = 0.0272; C1913 = 0.0295; C1914 = 0.0318; C1915 = 0.0341; C1916 = 0.0364; C1917 = 0.0387; C1918 = 0.0410; C1920 = 0.0433; C1921 = 0.0456; C1922 = 0.0479; C1923 = 0.0502;
%Oscillator 20%
a20 = 0.20; omega20 = 20; C201 = 0.020; C202 = 0.043; C203 = 0.066; C204 = 0.089; C205 = 0.0112; C206 = 0.0135; C207 = 0.0158; C208 = 0.0181; C209 = 0.0204; C2010 = 0.0227; C2011 = 0.0250; C2012 = 0.0273; C2013 = 0.0296; C2014 = 0.0319; C2015 = 0.0342; C2016 = 0.0365; C2017 = 0.0388; C2018 = 0.0411; C2019 = 0.0434; C2021 = 0.0457; C2022 = 0.0480; C2023 = 0.0503;
%Oscillator 21%
a21 = 0.21; omega21 = 21; C211 = 0.021; C212 = 0.044; C213 = 0.067; C214 = 0.090; C215 = 0.0113; C216 = 0.0136; C217 = 0.0159; C218 = 0.0182; C219 = 0.0205; C2110 = 0.0228; C2111 = 0.0251; C2112 = 0.0274; C2113 = 0.0297; C2114 = 0.0320; C2115 = 0.0343; C2116 = 0.0366; C2117 = 0.0389; C2118 = 0.0412; C2119 = 0.0435; C2120 = 0.0458; C2122 = 0.0481; C2123 = 0.0504;
%Oscillator 22%
a22 = 0.22; omega22 = 22; C221 = 0.022; C222 = 0.045; C223 = 0.068; C224 = 0.091; C225 = 0.0114; C226 = 0.0137; C227 = 0.0160; C228 = 0.0183; C229 = 0.0206; C2210 = 0.0229; C2211 = 0.0252; C2212 = 0.0275; C2213 = 0.0298; C2214 = 0.0321; C2215 = 0.0344; C2216 = 0.0367; C2217 = 0.0390; C2218 = 0.0413; C2219 = 0.0436; C2220 = 0.0459; C2221 = 0.0482; C2223 = 0.0505;
%Oscillator 23%
a23 = 0.23; omega23 = 23; C231 = 0.023; C232 = 0.046; C233 = 0.069; C234 = 0.092; C235 = 0.0115; C236 = 0.0138; C237 = 0.0161; C238 = 0.0184; C239 = 0.0207; C2310 = 0.0230; C2311 = 0.0253; C2312 = 0.0276; C2313 = 0.0299; C2314 = 0.0322; C2315 = 0.0345; C2316 = 0.0368; C2317 = 0.0391; C2318 = 0.0414; C2319 = 0.0437; C2320 = 0.0460; C2321 = 0.0483; C2322 = 0.0506;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x1(1) = 0.5; y1(1) = 0.5; x2(1) = 0.6; y2(1) = 0.6; x3(1) = 0.7; y3(1) = 0.7; x4(1) = 0.8; y4(1) = 0.8; x5(1) = 0.9; y5(1) = 0.9; x6(1) = 1; y6(1) = 1; x7(1) = 1.1; y7(1) = 1.1; x8(1) = 1.2; y8(1) = 1.2; x9(1) = 1.3; y9(1) = 1.3; x10(1) = 1.4; y10(1) = 1.4; x11(1) = 1.5; y11(1) = 1.5; x12(1) = 1.6; y12(1) = 1.6; x13(1) = 1.7; y13(1) = 1.7; x14(1) = 1.8; y14(1) = 1.8; x15(1) = 1.9; y15(1) = 1.9; x16(1) = 2; y16(1) = 2; x17(1) = 2.1; y17(1) = 2.1; x18(1) = 2.2; y18(1) = 2.2; x19(1) = 2.3; y19(1) = 2.3; x20(1) = 2.4; y20(1) = 2.4; x21(1) = 2.5; y21(1) = 2.5; x22(1) = 2.6; y22(1) = 2.6; x23(1) = 2.7; y23(1) = 2.7;
for i = 2:1000
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
plot(x1)
1 个评论
采纳的回答
NAVNEET NAYAN
2023-1-10
编辑:NAVNEET NAYAN
2023-1-10
I tried running your code in the command window and I was getting the same problem. As per me, when the value of i will be 3, it will ask for the value of x1(2), y1(2)..., x23(2) and y23(2). When the code will run, you will get the subsequent values of x1(2), y1(2), x1(3), y1(3) and so on. But your code doesn't get the values of x2(2), y2(2),vx2(3), y2(3) and so on. This applies for x3(2), y3(2) and so on and till x23(2), y23(2) and so on.
If you will try to run your code "for i=2:2 ", it will run, but from i=3 it won't, just because it doesn't get input x2(2), x3(2),...x22(2),x23(2),...y2(2), y3(2),...y22(2),y23(2),...and so on.
Hope you get my point.
3 个评论
NAVNEET NAYAN
2023-1-10
If the values of x2,....x23 and y2,...y23 doesn't change the following for loop will work
for i = 2:1000
x1(i) = x1(i-1) + ( ( a1 - x1(i-1)^2 - y1(i-1)^2 )*x1(i-1) - omega1*y1(i-1) + G*C12*( x2(1) - x1(i-1) ) + G*C13*( x3(1) - x1(i-1) ) + G*C14*( x4(1) ) - x1(1) + G*C15*( x5(1) - x1(i-1) ) + G*C16*( x6(1) - x1(i-1) ) + G*C17*( x7(1) - x1(i-1) ) + G*C18*( x8(1) - x1(i-1) ) + G*C19*( x9(1) - x1(i-1) ) + G*C110*( x10(1) - x1(i-1) ) + G*C111*( x11(1) - x1(i-1) ) + G*C112*( x12(1) - x1(i-1) ) + G*C113*( x13(1) - x1(i-1) ) + G*C114*( x14(1) - x1(i-1) ) + G*C115*( x15(1) - x1(i-1) ) + G*C116*( x16(1) - x1(i-1) ) + G*C117*( x17(1) - x1(i-1) ) + G*C118*( x18(1) - x1(i-1) ) + G*C119*( x19(1) - x1(i-1) ) + G*C120*( x20(1) - x1(i-1) ) + G*C121*( x21(1) - x1(i-1) ) + G*C122*( x22(1) - x1(i-1) ) + G*C123*( x23(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(1) - y1(i-1) ) + G*C13*( y3(1) - y1(i-1) ) + G*C14*( y4(1) ) - y1(i-1) + G*C15*( y5(1) - y1(i-1) ) + G*C16*( y6(1) - y1(i-1) ) + G*C17*( y7(1) - y1(i-1) ) + G*C18*( y8(1) - y1(i-1) ) + G*C19*( y9(1) - y1(i-1) ) + G*C110*( y10(1) - y1(i-1) ) + G*C111*( y11(1) - y1(i-1) ) + G*C112*( y12(1) - y1(i-1) ) + G*C113*( y13(1) - y1(i-1) ) + G*C114*( y14(1) - y1(i-1) ) + G*C115*( y15(1) - y1(i-1) ) + G*C116*( y16(1) - y1(i-1) ) + G*C117*( y17(1) - y1(i-1) ) + G*C118*( y18(1) - y1(i-1) ) + G*C119*( y19(1) - y1(i-1) ) + G*C120*( y20(1) - y1(i-1) ) + G*C121*( y21(1) - y1(i-1) ) + G*C122*( y22(1) - y1(i-1) ) + G*C123*( y23(1) - y1(i-1) ) )*dt;
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!