fractional-order,Index exceeds the number of array elements (1)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi
Good time
I wrote this code but it gives an error
Please help me
thank you
%%
n=100;
u1=[0,0]';
X1=[-4,-2,0]';
a=0.9;
h=0.9;
cp1=1;cp2=1;cp3=1;
for j=1:n
c1(j)=(1-(1+a)/j)*cp1;
c2(j)=(1-(1+a)/j)*cp2;
c3(j)=(1-(1+a)/j)*cp3;
cp1=c1(j); cp2=c2(j); cp3=c3(j);
end
% initial conditions setting:
v1(1)=u1(1);
w1(1)=u1(2);
x1(1)=X1(1); y1(1)=X1(2); z1(1)=X1(3);
% calculation of phase portraits /numerical solution/:
for i=2:n
x1(i)=h*cos(z1(i-1))*v1(i-1) - memo(x1, c1, i);
y1(i)=h*sin(z1(i-1))*v1(i-1)-memo(y1, c2, i);
z1(i)=h*w1(i-1)-memo(z1, c3, i) ;
end
%%
function [yo] = memo(r, c, k)
%
temp = 0;
for j=1:k-1
temp = temp + c(j)*r(k-j);
end
yo = temp;
%
%%%%% error
Index exceeds the number of array elements (1).
Error in exocstrstateFcnCT1 (line 28)
x1(i)=h*cos(z1(i-1))*v1(i-1) - memo(x1, c1, i);
0 Kommentare
Antworten (1)
Walter Roberson
am 23 Dez. 2020
You only initialize
v1(1)=u1(1);
and you do not assign to any other entry in v1, so when i becomes 3, v1(i-1) becomes v1(2) which does not exist.
11 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!