Help with double for loop

1 回表示 (過去 30 日間)
José Salazar
José Salazar 2021 年 2 月 22 日
コメント済み: José Salazar 2021 年 2 月 25 日
Hi y'all
I have a problem in which I must use a double for loop for this equation:
roCpdT/dt=-vxroCpdT/dx-UA(T-Tv)
It's for a heat exchanger where :
  • ro density of water
  • Cp Heat capacity of water
  • dT/dt Change of temperature as a function of time
  • vx Flux velocity inside the inner tube of the heat exchanger
  • dT/dx Change of temperature as a function of space
  • U Global heat transfer coefficient
  • A Trasnfer area
  • T Temperature of a certain point in space at a certain time
  • Tv Steam temperature
So, I must use a double ¨for¨ loop to graph the function between x = [0 40] meters and within a time of t = [0 : 100 : 2000] seconds. Please, How can I do it using the Euler method, and also, how can I plot the results (Preferebly 1 curve per time interval)? Thanks!
  2 件のコメント
darova
darova 2021 年 2 月 22 日
Do you have a difference scheme?
José Salazar
José Salazar 2021 年 2 月 22 日
Something like it:
dT/dx = (T(j+1) - T(j)) / deltax
dT/dt = (T(i+1) - T(i)) / deltat
and the third equation in which is combined both time and space variations of temperature. The variable that I need to find (solve for) it's T(i+1)(j+1). Please help me

サインインしてコメントする。

回答 (1 件)

darova
darova 2021 年 2 月 22 日
I'll give you a start
T= zeros(m,n); % preallocation
T(1,:) = % initial condition
for i = 1:m-1
for j = 1:n-1
T(i+1,j+1) = T(i,j+1) + dt/dx*Vx*(T(i,j+1)-T(i,j)) - UA*(T(i,j+1)-Tv)
end
end
note: dt/dx part should be small
  1 件のコメント
José Salazar
José Salazar 2021 年 2 月 25 日
Hi! I tried that but got some values with no logic at all. My temperature shouldn't be smaller than 25°C or above 100°C and yet I still got values outside of those limits. Can you please help me? Also I tried to plot the results because I want a curve for each time interval, but couldn't do it. Please hel me. This is what I got:
clc; clear; close all
m = 1000; %Time domain
n = 40; %Lenght of HEX domain
T = zeros(m,n);
U = 3400;
Di = 0.03; %Diameter of tube
De = 0.065; %Diameter of shell
L = 40; %Max lenght of HEX
vz = 2; %Velocity of water in inner tube
Tv = 100; %Steam temperature
T(1,:) = 25; %Prealocación
Ts = 100; %Temperature of water leaving HEX
Tset = 100; %Set temperature
d = 977.5; %Density of water
Cp = 4181; %Cp of water
At = pi*Di*L; %Sectional area
deltat = 100; %segundos
deltaz = 1; %metros
t(1) = 0;
z(1) = 0;
for i = 1 : m-1
for j = 1 : n-1
T(i+1,j+1) = T(i,j+1) + ((vz * (T(i,j+1)-T(i,j))/deltaz)-((U*At)/(d*Cp))*(T(i,j+1)-Tv))*deltat;
z(i+1) = z(i) + deltaz;
t(i+1) = t(i) + deltat;
end
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by