MATLAB: Matlab shows “Index exceeds matrix dimensions”

indexmatrix

%Linearized system
SIGMA = 10;
R = 28;
BETA = 8/3;
x=0;
y=1;
z=0;
A=[-SIGMA, SIGMA, 0;
R-z, -1, -x;
y, x, -BETA];
j=3;
dim=3;
N=3;
[Q,~] = qr(rand(dim,j),0);
c = [zeros(1,j-1) 1];
for i=1:N,
QNew = A(: ,(i-1)*dim+1:i*dim)*Q;
[Q,~] = qr(QNew,0);
end
Q0=Q;
for i = (N+1):(2*N+1),
QNew = A(: ,(i-1)*dim +1: i*dim)*Q;
[Q,R] = qr(QNew ,0);
AllR = horzcat(R,AllR);
end
numOfR = size(AllR,2)/j;
for i = 1:numOfR
R = AllR(: ,(i-1)*j+1:i*j);
cNew = R\c;
c = cNew/norm(cNew);
end
w=Q0*c;
I get the error "Index exceeds matrix dimensions.
Error in ginelli (line 21) QNew = A(: ,(i-1)dim+1:idim)*Q;"
Thanks in advance!

Best Answer

  • A is 3-by-3. But i*dim can be 9 in the i=1:N loop or 21 in the i = (N+1):(2*N+1) loop. It doesn't have that many columns (9 or 21) - it has only 3.