Attempted to access U(2,0); index must be a positive integer or logical.

1 Ansicht (letzte 30 Tage)
Zuhaa Naz
Zuhaa Naz am 6 Mär. 2020
Bearbeitet: Walter Roberson am 6 Mär. 2020
here is my Guass-seidal program for poisson equation, how will i overcome this error.
function U=Guassseidal(n,m,a,b,c,d,tol,N)
n=3; %input('enter the value of n= ');
m=3; %input('enter the value of m= ');
a=0; % input('enter the value of a= ');
b=3; %input('enter the value of b= ');
c=0; %input('enter the value of c= ');
d=3; %input('enter the value of d= ');
tol=0.001; %input('enter the value of tolerance= ');
N=2; %input('enter the total number of iterations = ');
A=-10; %input('input F(x,y)::::if your fuction is variable use inline('') ');
Bc1=0;%input('enter the Boundary condition at U(x,c) ');
Bc2=0;%input('enter the Boundary condition at U(x,d) ');
Bc3=0;%input('enter the Boundary condition at U(a,y) ');
Bc4=0;%input('enter the Boundary condition at U(b,y) ');
h=(b-a)/n;
k=(d-c)/m;
for i=1:n-1
for j=1:m-1
x(i)=a+i*h;
y(i)=c+j*k;
end
end
for i=1:n-1
for j=1:m-1
U(i,j)=0;
end
end
for i=2:n-1
U(i,c)=Bc1;
U(i,d)=Bc2;
for j=1:m
U(a,j)=Bc3;
U(b,j)=Bc4;
end
end
alpha=2*(1+h^2/k^2);
K=1;
while K<=N
errchk=0;
for j=2:m-3
for i=2:n-3
S=((-h^2)*A+U(i-1,j)+U(i+1,j)+(0.5*alpha-1)*(U(i,j-1)+U(i,j+1)))/alpha;
if errchk<abs(S-U(i,j))
errchk=abs(S-U(i,j));
U(i,j)=S;
if errchk<=tol
end
for j=1:m-1
for i=1:n-1
disp(U)
disp('succesfully complete with solution ')
end
end
end
end
K=K+1;
end
disp('number of iterations exceed, unsuccessful completion')
end
end
  7 Kommentare
Zuhaa Naz
Zuhaa Naz am 6 Mär. 2020
Yes you are absolutely right. Will you please tell me which additional code is used to deal with boundary conditions
Walter Roberson
Walter Roberson am 6 Mär. 2020
Bearbeitet: Walter Roberson am 6 Mär. 2020
I am not familiar enough with the mathematics to say what the boundary conditions should be. But it probably involves the Bc* variables.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by