필터 지우기
필터 지우기

How to fix the error (Index exceeds matrix dimensions)?

조회 수: 1 (최근 30일)
Omar B.
Omar B. 2019년 9월 19일
댓글: Omar B. 2019년 9월 19일
could you please check my code. I got the following error
Index exceeds matrix dimensionshow .
Error in NnNonSymmetricLanczos (line 17)
r=A*V(:,j)-alpha*V(:,j)-gamma*V(:,j-1);
function [alpha,beta,gamma,T] = alg(A,v,n)
n=4;
c = ones(n,1);
t = ones(1,n)./(1:n);
A = toeplitz(c,t);
v = randn(n,1);
V=v; W=v/norm(v)^2;
beta=0; gamma=0;
alpha=W(:,1)'*A*V(:,1); T(1,1)=alpha;
for j=1:n
if j==1
r=A*V(:,j)-alpha*V(:,j);
p=A'*W(:,j)-alpha*W(:,j);
else
r=A*V(:,j)-alpha*V(:,j)-gamma*V(:,j-1);
p=A'*W(:,j)-alpha*W(:,j)-beta*W(:,j-1);
end
beta=norm(r);
gamma=r'*p/beta;
end
T(j+1,j)=beta;
T(j,j+1)=gamma;
V=[V,r/beta];
W=[W,p/gamma];
alpha=W(:,j+1)'*A*V(:,j+1);
T(j+1,j+1)=alpha;
end

채택된 답변

Matt J
Matt J 2019년 9월 19일
V and W only have a single column, but you are indexing them V(:,j) and W(:,j) at j>1.
  댓글 수: 3
Matt J
Matt J 2019년 9월 19일
편집: Matt J 2019년 9월 19일
You currently have these two lines creating a one-column matrix, V.
v = randn(n,1);
V=v;
If V should have n columns, then you must change something here.
Omar B.
Omar B. 2019년 9월 19일
Thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by