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.

2 views (last 30 days)
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

Answers (1)

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

Community Treasure Hunt

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

Start Hunting!