Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
Junseob Kim
Junseob Kim el 23 de En. de 2020
Comentada: Walter Roberson el 23 de En. de 2020
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 comentarios
James Tursa
James Tursa el 23 de En. de 2020
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.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 23 de En. de 2020
Editada: Walter Roberson el 23 de En. de 2020
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 comentarios
Walter Roberson
Walter Roberson el 23 de En. de 2020
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by