フィルターのクリア

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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by