Index exceeds the number of array elements. Index must not exceed 1.
Mostrar comentarios más antiguos
Please help to resolve the error.
clear all; close all; clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Simulation %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%value of constants
a1=0.7;a2=0.1;
omega1=20;omega2=40;
G=10;C12=0;C21=0.003;
dt=0.01; %step size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x1rec(1)=0.5;
y1rec(1)=0.5;
x2rec(1)=0.5;
y2rec(1)=0.5;
for i=2:1000
x1rec(i)=x1rec(i-1)+((a1-x1rec(i-1)^2-y1rec(i-1)^2)*x1rec(i-1)-omega1*y1rec(i-1)+G*C12*(x2rec(i-1)-x1rec(i-1)))*dt;
x2rec(i)=x2rec(i-1)+((a2-x2rec(i-1)^2-y2rec(i-1)^2)*x2rec(i-1)-omega2*y2rec(i-1)+G*C21*(x1rec(i-1)-x2rec(i-1)))*dt;
end
Respuesta aceptada
Más respuestas (1)
you can initialize your array before the loop
a1=0.7;a2=0.1;
omega1=20;omega2=40;
G=10;C12=0;C21=0.003;
dt=0.01; %step size
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
numOfIterations=1000;
x1rec=zeros(1,numOfIterations);
y1rec=zeros(1,numOfIterations);
x2rec=zeros(1,numOfIterations);
y2rec=zeros(1,numOfIterations);
x1rec(1)=0.5;
y1rec(1)=0.5;
x2rec(1)=0.5;
y2rec(1)=0.5;
for i=2:numOfIterations
x1rec(i)=x1rec(i-1)+((a1-x1rec(i-1)^2-y1rec(i-1)^2)*x1rec(i-1)-omega1*y1rec(i-1)+G*C12*(x2rec(i-1)-x1rec(i-1)))*dt;
x2rec(i)=x2rec(i-1)+((a2-x2rec(i-1)^2-y2rec(i-1)^2)*x2rec(i-1)-omega2*y2rec(i-1)+G*C21*(x1rec(i-1)-x2rec(i-1)))*dt;
end
disp('finish')
1 comentario
Haya Ali
el 6 de Feb. de 2023
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!