Why while end error does not work in my code??

clear clc
L=0.02;H=40;dx=0.01;dy=dx;dt=15
nx=uint32(L/dx+1);ny=uint32(H/dy+1);rx=dt/dx^2;ry=dt/dy^2;
k=28;alfa=12.5*10^-6;g=5*10^6;Ts=30;h=45
[X Y]=meshgrid(linspace(0,L,nx),linspace(0,H,ny));Tint=200;T=Tint*ones(ny,nx);
Tleft=0;Tright=Tint;Ttop=Tint;Tbottom=Tint;
T(:,1)=Tleft;T(:,end)=Tright;T(1,:)=Ttop;T(end,:)=Tbottom;Fo=alfa*dt*(dx^2);
time=0;n=time/dt;
err=1
tol=10^-1
while err>tol
n=n+1
Tn=T;
for i=2:nx-1
for j=2:ny-1
T(j,i)=Tn(j,i)+((Tn(j,i+1)+Tn(j,i-1)+Tn(j-1,i)+Tn(j+1,i)-4*Tn(j,i))+g*dx^2/k)*Fo
T(j,end)=Fo*((g*dx^2)/k - (2*h*(Tn(j,end) - Ts)*dx)/k - 2*Tn(j,end) + 2*Tn(j,end-1) + Tn(j,end)/Fo)
end
end
err = max(max(abs(Tn - T)))
end
İt is weird situation. My code is working but it does not stop. My error is smaller than 10^-2 but it does not stop.

1 commentaire

Rik
Rik le 26 Août 2020
On my copy of Matlab it does stop. To massively increase the speed of the code I did put semicolons in the inner loop.

Connectez-vous pour commenter.

 Réponse acceptée

Rik
Rik le 26 Août 2020

0 votes

Based on your now deleted comment ("Yeah, when i put semicolons it worked."):
The cause of the loop seeming to be stuck is that you printed the entire T array to your command window. This is fast, but it does take time. By putting semicolons in your code to suppress the output you avoid this, so the for loops finish in a reasonable time.

1 commentaire

esat gulhan
esat gulhan le 26 Août 2020
well, at least with semicolons i can reach my aim. thanx anyway

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by