Borrar filtros
Borrar filtros

Help with iteration...

1 visualización (últimos 30 días)
Walter Manns
Walter Manns el 13 de Nov. de 2011
I'll show code first, then explain.
H = input('Altura de la Conserva [m] = ');
D = input('Diámetro de la Conserva [m] = ');
Alpha = input('Coeficiente de Difusión de Calor [m^2/s] = ');
dr = D/8; %Diferencial del radio [m].
dz = H/8; %Diferencial de la altura [m].
dt = 7; %Diferencial de tiempo [s].
tp = input('Tiempo de proceso [s] = ');
Tc = input('Temperatura de final de proceso [°C] = ');
Tf = input('Temperatura de Enfriamiento [°C] = ');
Ti = input('Temperatura inicial de la conserva [°C] = ');
Ta = input('Temperatura Ambiente [°C] = ');
CUT = input('Tiempo de Come Up Time (CUT) [s] = ');
T(:,:,1)= Ti*ones(5,5);
time(1) = 0;
time(2) = dt;
t=1;
Tcut(1) = Ta;
Tcut(2) = Ta;
Tr = input('Temperatura de referencia Fo [°C] = ');
z = input('Z de referencia Fo [°C] = ');
Fo = input('Fo mínimo requerido [s] = ');
ff = 120;
foo = 0;
while time(t+1)<=tp %Condición de finalización del proceso.
tempf = T(1,1,:);
tempp = T(5,5,:);
Tpf = tempf(:,:);
Tpp = tempp(:,:);
for k=1:(t-1)
fo(k) = ((time(k+1)-time(k))/2)*(10^((Tpf(k+1)-Tr)/z)+10^((Tpf(k)-Tr)/z));
foo = sum(fo);
if foo<ff
tc = tp;
elseif foo>=ff
ctime = time(k);
tc = ctime;
end
end
for i=1:5 %Índice en la dirección de r.
for j=1:5 %Índice en la dirección de z
if i==5&&time(t+1)<CUT
T(i,j,t+1) = Tcut(t);
elseif j==5&&time(t+1)<CUT
T(i,j,t+1) = Tcut(t);
elseif i==5&&time(t+1)<=tc&&time(t+1)>=CUT
T(i,j,t+1) = Tc;
elseif j==5&&time(t+1)<=tc&&time(t+1)>=CUT
T(i,j,t+1) = Tc;
elseif i==5&&time(t+1)>tc
T(i,j,t+1) = Tf;
elseif j==5&&time(t+1)>tc
T(i,j,t+1) = Tf;
elseif i>1&&i<5&&j>1&&j<5
T(i,j,t+1) = Alpha*dt*((T(i+1,j,t)-2*T(i,j,t)+T(i-1,j,t))/(dr)^2 + (1/((i-1)*dr))*((T(i+1,j,t)-T(i,j,t))/(2*dr)) + (T(i,j+1,t)-2*T(i,j,t)+T(i,j-1,t))/(dz)^2) + T(i,j,t);
elseif i==1&&j>1&&j<5
T(i,j,t+1) = Alpha*dt*(4*(T(i+1,j,t)-T(i,j,t))/(dr)^2 + (T(i,j+1,t)-2*T(i,j,t)+T(i,j-1,t))/(dz)^2) + T(i,j,t);
elseif i>1&&i<5&&j==1
T(i,j,t+1) = Alpha*dt*((T(i+1,j,t)-2*T(i,j,t)+T(i-1,j,t))/(dr)^2 + (1/((i-1)*dr))*((T(i+1,j,t)-T(i,j,t))/(2*dr)) + 2*(T(i,j+1,t)-T(i,j,t))/(dz)^2) + T(i,j,t);
elseif i==1&&j==1
T(i,j,t+1) = 2*Alpha*dt*(2*(T(i+1,j,t)-T(i,j,t))/(dr)^2 + (T(i,j+1,t)-T(i,j,t))/(dz)^2) + T(i,j,t);
end
end
end
t = t+1;
time(t+1) = time(t)+dt;
Tcut(t+1) = (((Tc - Ta)/CUT)*(t*dt)+Ta);
end
I have to copy it all so you can undertand better the problem. It is a heating process.
This section:
for k=1:(t-1)
fo(k) = ((time(k+1)-time(k))/2)*(10^((Tpf(k+1)-Tr)/z)+10^((Tpf(k)-Tr)/z));
foo = sum(fo);
if foo<ff
tc = tp;
elseif foo>=ff
ctime = time(k);
tc = ctime;
end
end
Start the "cooling time", when foo is more than ff. I want that, after my entire while loop has ended, foo is compared with the initial Fo input, and if foo<Fo, ff = ff+5;, and start my while loop again from that point (i want to start from that point because it's useless to start from the start, it will make the code only slower).
If you want to try it out, use these values:
H = 0.1 D = 0.1 Alpa = 10^(-7)
tp = 24000 Tc = 120 Tf = 16 Ti = 16 Ta = 16 CUT = 600 Tr = 121.1 z = 10 Fo = 480 (wich actually does nothing right now)
Don't modify Alpha too much specially, or it goes unstable.
Regards... and thanks for the helps.
  1 comentario
Jan
Jan el 13 de Nov. de 2011
What is your question?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements 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!

Translated by