Breaking loop at a desired value
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Turgut Ataseven
el 28 de Mayo de 2022
Respondida: Walter Roberson
el 28 de Mayo de 2022
Hi.
I am trying to modify my FTSC methodd code so that it breaks when 14.9<T(11,11,k+1)<15.1 condition is satisfied. Since time interval is unknown,time variable t, time step variable p and variables including p and t are commented out. I arbitrarily picked p values to obtain the solution but that is not how the code should work. How must the code be modified so that it is in an infinite loop and breaks when 14.9<T(11,11,k+1)<15.1 condition is satisfied?
Thanks.
%t=4; % Total time (s) % Commented out
delta_t=0.0003787; % Time step
L=2; % Length of each edge
delta_x=0.1; % Spacing
% Boundary temperatures
T1=10;
T2=10;
T3=10;
T4=10;
% Initial temperature
T5=400;
n=((L/delta_x)+1)^2; % Total no of nodes
m=sqrt(n); % Number of nodes in each row and column
%r1=(t/delta_t)+1; % Number of time steps, time step again %%%%%%%%
%p=round(r1); % Number of time steps (rounded)
r=0.00573;
% Placing initial and boundary conditions
%T=zeros(m,m,p); % Pre-allocating, commented out
for k=1:16562 % Time-step loop,this line was k=1:p normally
for i=1:m % x coord loop
for j=1:m % y coord loop
if(i==1)&&(j==1)
T(i,j,k)=(T4+T1)/2;
elseif(i==1)&&(j==m)
T(i,j,k)=(T2+T1)/2;
elseif(i==m)&&(j==m)
T(i,j,k)=(T2+T3)/2;
elseif(i==m)&&(j==1)
T(i,j,k)=(T4+T3)/2;
elseif(i==1&&(j>1&&j<m))
T(i,j,k)=T1;
elseif(j==m&&(i>1&&i<m))
T(i,j,k)=T2;
elseif(i==m&&(j>1&&j<m))
T(i,j,k)=T3;
elseif(j==1&&(i>1&&i<m))
T(i,j,k)=T4;
else
T(i,j,k)=T5;
end
end
end
end
% Solution
for k=1:16562 % This line was k=1:p normally too
for i=2:m-1
for j=2:m-1
T(i,j,k+1)= T(i,j,k)+r*( T(i-1,j,k)+ T(i+1,j,k)+ T(i,j+1,k)+ T(i,j-1,k)-4* T(i,j,k));
if(T(11,11,k+1)>14.9&&T(11,11,k+1)<15.1)
break
end
end
end
end
imagesc(T(:,:,16562)); % This line was imagesc(T(:,:,p))
T(11,11,16562) % This line was (T(:,:,p))
colorbar;
title('Temperature Profile')
0 comentarios
Respuesta aceptada
Walter Roberson
el 28 de Mayo de 2022
keepgoing = true;
for k =...
for i =...
for j =...
if i==11 && j==11 && T(11,11,k+1)>14.9 && T(11,11,k+1)<15.1
keepgoing =false;
break;
end %if
end %j
if ~keepgoing; break; end
end %i
if ~keepgoing; break; end
end %k
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!