Breaking loop at a desired value
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2022년 5월 28일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!