フィルターのクリア

Laplace solved by Gauss-Seidel

3 ビュー (過去 30 日間)
Kornelija Paulauskaite
Kornelija Paulauskaite 2017 年 12 月 6 日
The code delivers the same answer for any choice of NX or NY. There's a problem somewhere but I cannot find it..
NX=100; NY=100; Lx=5; Ly=5; x=linspace(0,Lx,NX); y=linspace(0,Ly,NY); u=zeros(NX,NY); u1=0; u2=900; u3=0; u4=0; err=1; k=0; tic; while max(err(:))>0 k=k+1;
uold=u;
for i=2:NX-1
for j=2:NY-1
u(i,j)=.25*(u(i+1,j)+u(i+1,j)+u(i,j+1)+u(i,j-1));
u(:,NX)=u1;
u(:,1)=u2;
u(1,:)=u3;
u(NY,:)=u4;
unew=u;
err=abs((uold-unew)./unew);
end
end
end
toc;
for i=1:NX
for j=1:NY
n=i+(j-1)*NX;
ui(i,j)=u(n);
end
end
surf(x,y,ui')
fprintf('number of iterations is :%f',k)
timetaken=toc

回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by