필터 지우기
필터 지우기

How to stop my iteration Tn(j,i)=Tn+1(j,i)

조회 수: 1 (최근 30일)
esat gulhan
esat gulhan 2020년 8월 24일
편집: Alan Stevens 2020년 8월 24일
clear clc
dx=0.5
nx=uint32(5/dx+1)
ny=uint32(5/dx+1)
[X Y]=meshgrid(linspace(0,5,nx),linspace(0,5,ny))
Tint=0
T=Tint*ones(ny,nx)
Tleft=100
Tright=0
Ttop=0
Tbottom=0
T(:,1)=Tleft
T(:,end)=Tright
T(1,:)=Ttop
T(end,:)= Tbottom
k=3
itr=200
for k=1:itr
for i=2:nx-1
for j=2:ny-1
T(j,i)=((T(j-1,i)+T(j+1,i)+T(j,i-1)+T(j,i+1))/4)
end
end
end
[Xq Yq]= meshgrid(linspace(0,5,nx*10),linspace(0,5,ny*10));
colormap jet
Vq=interp2(X,Y,T,Xq,Yq,'cubic',0);
This is my code. My iteration 200 but i want my code stop when Tn(j,i)=Tn+1(j,i) . But i dont know how to break for end...

채택된 답변

Alan Stevens
Alan Stevens 2020년 8월 24일
편집: Alan Stevens 2020년 8월 24일
Replace your for loop by:
tol = 10^-6; % Or whatever is appropriate
err = 1;
while err>tol
Told = T;
for i=2:nx-1
for j=2:ny-1
T(j,i)=((T(j-1,i)+T(j+1,i)+T(j,i-1)+T(j,i+1))/4);
end
end
err = max(max(abs(T - Told)));
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by