Value in Array does not Change

4 views (last 30 days)
Vishakh Ranade
Vishakh Ranade on 4 Oct 2014
Commented: Vishakh Ranade on 4 Oct 2014
I'm simulating a Heat Exchanger Model with the HED Matrix in the program as discretized Heat Exchanger. The 1st row is the hot fluid matrix and 2nd row is the cold fluid matrix. The calculation is in a loop of timesteps. The temperature of the fluid changes as per the loss in enthalpy. But the temperature of the cold fluid does not change at all, it decreases at some timesteps when it should strictly increase. You can view the results at different time steps by tweaking the for loop with 't/j'. I have commented on the program, I'm stuck only on this, since the other part of program seems fine.
t = 25; % L/((m/rho)/CSArea); %Time for the fluid to cross Heat Exchanger
%Heat Transfer Coefficients
Hhot = 0.340;
Hcold = 0.400;
A = 1;
Cpcold = 4.179;
Cphot = 4.208;
%Initial Temperatures
Th = 363;
Tc = 303;
%number of fluids i
i = 1;
%discretization level; number of blocks fluid to be divided into j;
j = 100;
HED = zeros(i,j);
n=5; %timesteps
for j= 1:1:j
HED(i,j) = Th;
HED(i+1,j) = Tc;
end
Qrate = zeros(i,j);
for m = t/j:t/j:j*t/j
j=100;
for j =1:1:j
Qrate(i,j) = Hhot * A * (HED(i,j)-HED(i+1,j)); %Heat transfer Rate
end
Q1 = times(Qrate,t/j); %Heat transferred in timestep
for j = 0:1:j-1
%New Temperature of Cold Water after Heat Transfer
HED(i+1,j+1) = HED(i+1,j+1) + (Q1(i,j+1)/Cpcold);
%New Temperature of Hot Water after Heat Tranfer
HED(i,j+1) = HED(i,j+1) - (Q1(i,j+1)/Cphot);
end
for j=0:1:j-1
HED(i,j+1)=HED(i,j+2); %shifting row of hot fluid Row 1
HED(i+1,j+2)=HED(i+1,j+1); %shifting row of cold fluid Row 3
end
j=100;
HED(i,j) = Th;
HED(i+1,1) = Tc;
end
  1 Comment
the cyclist
the cyclist on 4 Oct 2014
The way that you use j as a constant and as a looping variable (and as the endpoint of that looping variable) is pretty confusing, and possibly the source of your bug. (MATLAB may interpret that correctly, but I'm not sure.)

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 4 Oct 2014
This is a guess, because I have not run your code, but is the very last line right?
HED(i+1,1) = Tc;
Is that "1" right, or should it be j?
  1 Comment
Vishakh Ranade
Vishakh Ranade on 4 Oct 2014
Thanks for your review, actually I figured the problem out soon. The problem was in the 'shifting row of cold" part. the problem was: 1st iteration : HED(2,2)=HED(2,1) 2nd iteration : HED(2,3)=HED(2,2) So the same value would be copied through the entire matrix.

Sign in to comment.

Categories

Find more on Fluid Network Interfaces Library in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!