Index exceeds the number of array elements. Index must not exceed 1.

39 vues (au cours des 30 derniers jours)
nune pratyusha
nune pratyusha le 24 Mai 2022
Commenté : nune pratyusha le 25 Mai 2022
function run_LE_FO_a(ne,ext_fcn,t_start,h_norm,t_end,x_start,h,q,a_min,a_max,n);
figure();
hold on;
ne=4;
ext_fcn=@LE_RF_a;
t_start=0;h_norm=0.02;t_end=1;
x_start=[0 0 1 1];h=0.2;q=1;
a_max=-11;
a_min=-12.2;
n=800;
p_step=(a_max-a_min)/n
a=a_min;
% for p1=1.1:0.1:1.3;
while a<=a_max
lp=FO_Lyapunov_a(ne,ext_fcn,0,0.2,1,[0 0 1 1],0.2,1,a)
a=a+p_step;
plot(a,lp,'.')
drawnow();
% end
end
function LE=FO_Lyapunov_a(ne,ext_fcn,t_start,h_norm,t_end,x_start,h,q,a);
% Memory allocation
x=zeros(ne*(ne+1),1);
x0=x;
% y0=x_start
c=zeros(ne,1);
gsc=c; zn=c;
n_it = round((t_end-t_start)/h_norm);
% Initial values
x(1:ne)=x_start;
i=1;
while i<=ne
x((ne+1)*i)=1.0;
i=i+1;
end
t=t_start;
% Main loop
it=1;
while it<=n_it
% Solutuion of extended ODE system of FO using FDE12 routine
[T,Y] = FDE12(q,ext_fcn,t,t+h_norm,[0 0 1 1],h,a);
t=t+h_norm;
Y=transpose(Y);
x=Y(size(Y,1),:); %solution at t+h_norm
i=1;
while i<=ne
j=1;
while j<=ne;
x0(ne*i+j)=x(ne*j+i);
j=j+1;
end;
i=i+1;
end;
% construct new orthonormal basis by gram-schmidt
zn(1)=0.0;
j=1;
while j<=ne
zn(1)=zn(1)+x0(ne*j+1)^2;
j=j+1;
end;
zn(1)=sqrt(zn(1));
j=1;
while j<=ne
x0(ne*j+1)=x0(ne*j+1)/zn(1);
j=j+1;
end
j=2;
while j<=ne
k=1;
while k<=j-1
gsc(k)=0.0;
l=1;
while l<=ne;
gsc(k)=gsc(k)+x0(ne*l+j)*x0(ne*l+k);
l=l+1;
end
k=k+1;
end
k=1;
while k<=ne
l=1;
while l<=j-1
x0(ne*k+j)=x0(ne*k+j)-gsc(l)*x0(ne*k+l);
l=l+1;
end
k=k+1;
end;
zn(j)=0.0;
k=1;
while k<=ne
zn(j)=zn(j)+x0(ne*k+j)^2;
k=k+1;
end
zn(j)=sqrt(zn(j));
k=1;
while k<=ne
x0(ne*k+j)=x0(ne*k+j)/zn(j);
k=k+1;
end
j=j+1;
end
% update running vector magnitudes
k=1;
while k<=ne;
c(k)=c(k)+log(zn(k));
k=k+1;
end;
% normalize exponent
k=1;
while k<=ne
LE(k)=c(k)/(t-t_start);
k=k+1;
end
i=1;
while i<=ne
j=1;
while j<=ne;
x(ne*j+i)=x0(ne*i+j);
j=j+1;
end
i=i+1;
end;
x=transpose(x);
it=it+1;
end
function f=LE_RF_a(t,x,a)
%p is the parameter
f=zeros(16,1);
b=0.4;c=11;d=6;e=130;f1=10;
x=X(1); y=X(2); z=X(3);w=X(4);
Y= [X(5), X(9), X(13), X(17);
X(6), X(10), X(14), X(18);
X(7), X(11), X(15), X(19);
X(8), X(12), X(16), X(20) ];
f(1)=a*y+(0.2+0.2*(abs(w))).*z;
f(2)=b*((w.^2)-13).*z-c*y;
f(3)=-d*x-e*y-f1*z;
f(4)=(z.^2)-w.^2;%Linearized system
Jac=[0 a 0.2+0.2*abs(w) 0.2*w.*z/abs(w);
0 -c b*((w.^2)-13) b*((w*2)-13).*z;
-d -e -f1 0;
0 0 2*z -2*w];
f(5:20)=Jac*Y;
error:>> run_LE_FO_a
p_step =
1.499999999999999e-03
Index exceeds the number of array elements. Index must not exceed 1.
Error in LE_RF_p1 (line 4)
X= [x(4) x(7) x(10);
Error in FDE12>f_vectorfield (line 300)
f = feval(Probl.fdefun,t,y,Probl.param) ;
Error in FDE12 (line 114)
f_temp = f_vectorfield(t0,y0(:,1),Probl) ;
Error in FO_Lyapunov_a (line 21)
[T,Y] = FDE12(q,ext_fcn,t,t+h_norm,[0 0 1 1],h,a);
Error in run_LE_FO_a (line 16)
lp=FO_Lyapunov_a(ne,ext_fcn,0,0.2,1,[0 0 1 1],0.2,1,a)
>>

Réponses (1)

Cris LaPierre
Cris LaPierre le 24 Mai 2022
See the full error message:
Index exceeds the number of array elements. Index must not exceed 1.
Error in LE_RF_p1 (line 4)
X= [x(4) x(7) x(10);
Apparently x is a scalar, not a vector, meaning it only has a single value. There error is because your code is requesting the 4th, 7th and 10th values, which don't exist.
x = 3;
% works
x(1)
ans = 3
% Your error
x(4)
Index exceeds the number of array elements. Index must not exceed 1.
  15 commentaires
Cris LaPierre
Cris LaPierre le 25 Mai 2022
Modifié(e) : Cris LaPierre le 25 Mai 2022
I have already explained this error in a previous comment.
To summarize, in the code you shared for your 3D equation, you create the x input dynamically and pass that into FDE12.
ne=3;
...
x=zeros(ne*(ne+1),1); % 12x1
...
[T,Y] = FDE12(q,ext_fcn,t,t+h_norm,x,h,p1);
in the code you shared for your 4D equation, you also dynamically create x, but then hardcode your input as a 1x4 vector.
ne=4;
x=zeros(ne*(ne+1),1); % 20x1
...
[T,Y] = FDE12(q,ext_fcn,t,t+h_norm,[0 0 1 1],h,a);
Use the same syntax in both cases to obtain the same behavior
nune pratyusha
nune pratyusha le 25 Mai 2022
it's working thank you so much

Connectez-vous pour commenter.

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Tags

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by