필터 지우기
필터 지우기

Index in position 4 exceeds array bounds (must not exceed 1).

조회 수: 2 (최근 30일)
Junseob Kim
Junseob Kim 2020년 1월 23일
댓글: Walter Roberson 2020년 1월 23일
for j = 2:ny-1
for i = 2:nx-1
Ex(i,j,n,1) = 150; %initial guess
Ey(i,j,n,1) = 200; %initial guess
for g = 1:gfinal-1
M11(i,j,n,g) = (1/(4*dt))*(g1+g2+g3)+(eps/dt)*(1+(alpha/kai0)*(3*(Ex(i,j,n+1,g))^2+(Ey(i,j,n+1,g))^2)+S(i,j,n+1));
M22(i,j,n,g) = (1/(4*dt))*(g1+g2+g3)+(eps/dt)*(1+(alpha/kai0)*((Ex(i,j,n+1,g))^2+3*(Ey(i,j,n+1,g))^2)+S(i,j,n+1));
M12(i,j,n,g) = ((2*eps)/dt)*alpha*kai0*Ex(i,j,n+1,g)*Ey(i,j,n+1,g);
M21(i,j,n,g) = ((2*eps)/dt)*alpha*kai0*Ex(i,j,n+1,g)*Ey(i,j,n+1,g);
M(:,:) = ([M11(i,j,n,g),M12(i,j,n,g); M21(i,j,n,g),M22(i,j,n,g)]);
Minv(:,:) = inv([M11(i,j,n,g),M12(i,j,n,g); M21(i,j,n,g),M22(i,j,n,g)]);
Ex(:,:,n+1,g+1) = Ex(:,:,n+1,g)- Minv(1,1)*X(i,j,n,g) - Minv(1,2)*Y(i,j,n,g);
if (abs(X(i,j,n)) <= tol && abs(Y(i,j,n)) <= tol)
break;
end
Ex(i,j,n,g+1) = Ex(i,j,n);
end
end
end
Hello. I am trying to solve newton's method problem.
But there's an error after M11(i,j,n,g) line. 'Index in position 4 exceeds array bounds (must not exceed 1).'
Can you help me with that problem?
Thanks!
  댓글 수: 2
James Tursa
James Tursa 2020년 1월 23일
Do this at the command line:
dbstop if error
Then run your code. When the error appears the code will pause will all variables intact. Examine them to see what their actual dimensions are, and then backtrack in your code to figure out why they are not the size that you expect.
Junseob Kim
Junseob Kim 2020년 1월 23일
Thank you so much!

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

답변 (1개)

Walter Roberson
Walter Roberson 2020년 1월 23일
편집: Walter Roberson 2020년 1월 23일
You define
Ex(i,j,n,1) = 150; %
but we have no reason to expect that on the line
M11(i,j,n,g) = (1/(4*dt))*(g1+g2+g3)+(eps/dt)*(1+(alpha/kai0)*(3*(Ex(i,j,n+1,g))^2+(Ey(i,j,n+1,g))^2)+S(i,j,n+1));
that
Ex(i,j,n+1,g)
exists -- in particular the n+1 is a problem.
  댓글 수: 3
Junseob Kim
Junseob Kim 2020년 1월 23일
Thanks you btw!!
Walter Roberson
Walter Roberson 2020년 1월 23일
You have the same issue for Ey except worse since you do not assign to Ey inside the loop and so are not growing Ey as you go.
You possibly also have problems accessing S.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by