i received an error (index must be a positive integer or logical. Error in Guassseidal3 (line 24) U(i,0)=0;) in solving PDE problems. plz help me to get out of this problem.

조회 수: 1 (최근 30일)
function U=Guassseidal(n,m,a,b,c,d,E,NO)
n=3;
m=3;
a=0;
b=3;
c=0;
d=3;
E=10^-3;
NO=1000;
h=(b-a)/n;
k=(d-c)/m;
for i=1:n-1
x(i)=a+i*h;
end
for j=1:m-1
y(j)=c+j*k;
end
for i=1:n-1
for j=1:m-1
U(i,j)=0;
end
end
for i=1:n-1
U(i,0)=0;
U(i,m)=0;
end
for j=1:m-1
U(0,j)=0;
U(n,j)=0;
end
K=1;
Alpha=2*(1+h*h/K*K);
while K<=NO
errchk=0;
for j=1:m-1
for i=1:n-1
S=(-h^2*(-10)+U(i-1,j)+U(i+1,j)+(0.5*Alpha-1)*(U(i,j-1)+U(i,j+1)))/Alpha;
end
if errchk<abs(S-U(i,j))
errchk=abs(S-U(i,j));
U(i,j)=S;
end
end
if errchk<=E
for j=1:m-1
for i=1:n-1;
output(u(i,j))
end
end
STOP
end
K=K+1;
end
Output('Maximum number of iteration exceed;procedure completed unsuccessfully');
STOP

답변 (1개)

Alex Mcaulley
Alex Mcaulley 2020년 3월 6일
0 is not a valid index in Matlab. To take the first element you should put 1:
U(i,1)=0;

카테고리

Help CenterFile Exchange에서 Geometry and Mesh에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by