How can I fix the error "Subscript indices must either be real positive integers or logicals. "

1 次查看(过去 30 天)
I'm trying to plot this differential equations system but I ran into this error. I have no idea to solve this problem however I think the problem is this two code line d1=0.15*sin(5*t(1i)); and d2=0.10*sin(7*t(1i));
%*********in func3.m********
function xdot = func3(t,x)
global DF1 DF2 d1 d2 fi1 fi2 Beta n
Beta=3; n=2; s1=1.5;
z1=.5; s2=1.8; z2=2;
DF1=0.3*(sin(1*pi*x(1))*sin(2*pi*x(2))*sin(3*pi*x(3))*sin(4*pi*x(4)));
DF2=0.2*(sin(1*pi*x(1))*sin(2*pi*x(2))*sin(3*pi*x(3))*sin(4*pi*x(4)));
d1=0.15*sin(5*t(1i));
d2=0.10*sin(7*t(1i));
u1(1i)=-((Beta(1i)+10)*abs(x(1))+2*abs(x(2))+s1(1i)+z1(1i))*sign(S(1));
u2(1i)=-(abs(x(1))+(x(1)*x(3))+(0.5+n(1i))*abs(x(4))+s2(1i)+z2(1i))*sign(S(2));
fi1=(1.4+0.2*sin(u1(1i)))*u1(1i);
fi2=(1.3+0.2*cos(u2(li)))*u2(1i);
xdot = zeros(4,1);
xdot(1)=10*(x(2)-x(1))+x(4);
xdot(2)=Beta(li)*x(1)-x(1)*x(3)-x(2)*DF1+d1+fi1;
xdot(3)=x(1)*x(2)-8/3*x(3);
xdot(4)=-x(1)*x(3)+n(li)*x(4)+DF2+d2+fi2;
end
%=====================================================
%***************in main.m****************
x=[0.1 2 3 -3];
t=0:0.02:7;
[T,x] = ode23('func3',[t(li) t(1i+1) t(1i+2)],x);
x=x(2,:);
X=x;
Beta(li+1)=abs(S(1))*abs(x(1));
s1(li+1)=abs(S(1));
z1(li+1)=abs(S(1));
s2(li+1)=abs(S(2));
z2(li+1)=abs(S(2));
n(li+1)=abs(x(4))*abs(S(2));
S1(li+1)=S(1);
S2(li+1)=S(2);
X(li+1,:)=x;
D1(li)=d1;
D2(li)=d2;
li;
figure(3)
plot(t(1:end-1),X)
legend('x_1(t)','x_2(t)','x_3(t)','x_4(t)')
figure(4)
plot(t(1:end-1),S1); hold on
plot(t(1:end-1),S2,'g');
legend('S_1(t)','S_2(t)')
figure(5)
plot(t(1:end-2),u1); hold on
plot(t(1:end-2),u2,'g');
legend('u_1(t)','u_2(t)')
Error in main (line 12)
[T,x] = ode23('func3',[t(1i+1) t(1i+2)],x);

回答(1 个)

Walter Roberson
Walter Roberson 2021-4-21
u1(1i)=-((Beta(1i)+10)*abs(x(1))+2*abs(x(2))+s1(1i)+z1(1i))*sign(S(1));
Beta(1i) is an attempt to index which does not exist.
MATLAB has absolutely no implied multiplication -- not even in the little pastic dimples left over from when the CDs were manufactured.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by