Index exceeds the number of array elements. Index must not exceed 101.
Please help me fix the following error: "Index exceeds the number of array elements. Index must not exceed 101." thank you very much!
%% Phase plane
clear all
clc
%% conditions
A=[-0.8 0.1;0.15 -0.15];
A_h=[-0.4 0.2;0.1 0.04];
A_d=[0.2 0.5;-0.3 0.05];
A_u=[0.1;-0.1];
A_c=[-76.0089 387.8927;75.3589 -387.9427];
stime=1.0;
endtime=30;
h=0.01;
t=-stime:h:endtime;
N_0=stime/h;
N_1=endtime/h;
N=N_0+N_1;
%bound=110;
for i=1:N+1
if i<=N_0+1;
x1(:,i)=0.05*sin((i-N_0-1)*h);
x2(:,i)=0.05*cos((i-N_0-1)*h);
else
d_1=floor(1.5+0.5*sin(1.5*i*h));
d_2=floor(2+cos(2.5*i*h));
if i<=4
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1));
else
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1)+A_h(1,1)*x1(:,i-d_1-1)+A_h(1,2)*x2(:,i-d_1-1)+(1/2)*(A_d(1,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-d_2)+x1(i-d_2+1)))+A_d(1,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-d_2)+x2(i-d_2+1)))));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1)+A_h(2,1)*x1(:,i-d_1-1)+A_h(2,2)*x2(:,i-d_1-1)+(1/2)*(A_d(2,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-2)+x1(i-3)+x1(i-4)))+A_d(2,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-2)+x2(i-3)+x2(i-4)))));
end
end
end
%% Plotting Graphs
figure
grid on
hold on
box on
plot(t,x1(1,:),’-g’,t,x2(1,:),’r-‘,’linewidth’,2.5)
hold on
xlabel(‘Time (t)’)
%ylabel(‘State responses’)
legend(‘x_{1}(t)’,’x_{2}(t)’);
xlim([0,30]);
ylim([-100,100]);
%Please help me fix the following error: "Index exceeds the number of array elements. Index must not exceed 101." thank you very much!
%% Phase plane
clear all
clc
%% conditions
A=[-0.8 0.1;0.15 -0.15];
A_h=[-0.4 0.2;0.1 0.04];
A_d=[0.2 0.5;-0.3 0.05];
A_u=[0.1;-0.1];
A_c=[-76.0089 387.8927;75.3589 -387.9427];
stime=1.0;
endtime=30;
h=0.01;
t=-stime:h:endtime;
N_0=stime/h;
N_1=endtime/h;
N=N_0+N_1;
%bound=110;
for i=1:N+1
if i<=N_0+1;
x1(:,i)=0.05*sin((i-N_0-1)*h);
x2(:,i)=0.05*cos((i-N_0-1)*h);
else
d_1=floor(1.5+0.5*sin(1.5*i*h));
d_2=floor(2+cos(2.5*i*h));
if i<=4
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1));
else
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1)+A_h(1,1)*x1(:,i-d_1-1)+A_h(1,2)*x2(:,i-d_1-1)+(1/2)*(A_d(1,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-d_2)+x1(i-d_2+1)))+A_d(1,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-d_2)+x2(i-d_2+1)))));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1)+A_h(2,1)*x1(:,i-d_1-1)+A_h(2,2)*x2(:,i-d_1-1)+(1/2)*(A_d(2,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-2)+x1(i-3)+x1(i-4)))+A_d(2,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-2)+x2(i-3)+x2(i-4)))));
end
end
end
%% Plotting Graphs
figure
grid on
hold on
box on
plot(t,x1(1,:),’-g’,t,x2(1,:),’r-‘,’linewidth’,2.5)
hold on
xlabel(‘Time (t)’)
%ylabel(‘State responses’)
legend(‘x_{1}(t)’,’x_{2}(t)’);
xlim([0,30]);
ylim([-100,100]);
% Please help me fix the following error: "Index exceeds the number of array elements. Index must not exceed 101." thank you very much!
%% Phase plane
clear all
clc
%% conditions
A=[-0.8 0.1;0.15 -0.15];
A_h=[-0.4 0.2;0.1 0.04];
A_d=[0.2 0.5;-0.3 0.05];
A_u=[0.1;-0.1];
A_c=[-76.0089 387.8927;75.3589 -387.9427];
stime=1.0;
endtime=30;
h=0.01;
t=-stime:h:endtime;
N_0=stime/h;
N_1=endtime/h;
N=N_0+N_1;
%bound=110;
for i=1:N+1
if i<=N_0+1;
x1(:,i)=0.05*sin((i-N_0-1)*h);
x2(:,i)=0.05*cos((i-N_0-1)*h);
else
d_1=floor(1.5+0.5*sin(1.5*i*h));
d_2=floor(2+cos(2.5*i*h));
if i<=4
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1));
else
x1(:,i)=x1(:,i-1)+h*(A_c(1,1)*x1(:,i-1)+A_c(1,2)*x2(:,i-1)+A_h(1,1)*x1(:,i-d_1-1)+A_h(1,2)*x2(:,i-d_1-1)+(1/2)*(A_d(1,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-d_2)+x1(i-d_2+1)))+A_d(1,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-d_2)+x2(i-d_2+1)))));
x2(:,i)=x2(:,i-1)+h*(A_c(2,1)*x1(:,i-1)+A_c(2,2)*x2(:,i-1)+A_h(2,1)*x1(:,i-d_1-1)+A_h(2,2)*x2(:,i-d_1-1)+(1/2)*(A_d(2,1)*(x1(i-1)+x1(i-d_2-1)+2*(x1(i-2)+x1(i-3)+x1(i-4)))+A_d(2,2)*(x2(i-1)+x2(i-d_2-1)+2*(x2(i-2)+x2(i-3)+x2(i-4)))));
end
end
end
%% Plotting Graphs
figure
grid on
hold on
box on
plot(t,x1(1,:),’-g’,t,x2(1,:),’r-‘,’linewidth’,2.5)
hold on
xlabel(‘Time (t)’)
%ylabel(‘State responses’)
legend(‘x_{1}(t)’,’x_{2}(t)’);
xlim([0,30]);
ylim([-100,100]);
% indexing MATLAB Answers — New Questions