Help with double for loop

조회 수: 6 (최근 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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by