How can I do an calculation where it uses the previous answer to calculate the next

3 次查看(过去 30 天)
So I want to model how a water tank changes in temperature when water is put in. So my Tank is 3600 L capacity and the flow into the water is 360 L/hr. If the water temperatre at the start is 290 Kelvin and the water temperature entering over 24 hours is as follows:
So this is what i need to do.
(3600*Tt+360*Twout/(3600+360)) %where Twout is as shown in the picture
%Tt is the variable that changes every hour so for the first hour Tt is equal to 290, but in the second hour it is equal to (3600*Tt+360*Twout)/ and so on for 24 hours
  2 个评论
Renato SL
Renato SL 2019-8-6
From what I understand:
  • Tt0 is known (your example is 290).
  • Tt1 = 3600*Tt0 + 360*Twout(1) / (3600 + 360)
  • Tt2 = 3600*Tt1 + 360*Twout(2) / (3600 + 360), and so on
Is this it?
rammah nagi
rammah nagi 2019-8-6
Yes this would work, i was just wondering whether there is a method that would do it without having to write all lines.

请先登录,再进行评论。

采纳的回答

Renato SL
Renato SL 2019-8-6
I would do something like this
Tt = 290; %temperature at the start
for i=1:24 %loop for 24 hours
temp = (3600*Tt(end) + 360*Twout(i)) / 3960; %basically, your formula
%Tt(end) to call the last value of Tt which is the result of the last computation
%Twout(i) for corresponding Twout value
Tt = [Tt temp]; %updating the value of Tt with the value of the last computation
end
  3 个评论
Renato SL
Renato SL 2019-8-6
Actually, please recheck the formula since the one that you write basically makes the value goes to infinity
temp = 3600*Tt(end) + 360*Twout(i) / (3600+360);
%basically temp = 3600*Tt (adds a minimum of 4 digits to the value) + a small addition
so that in my answer I put the brackets to the addition before the division
temp = (3600*Tt(end) + 360*Twout(i)) / (3600+360);
%so that temp = (hundreds of thousands) / (thousands)
% temp = a value in hundreds
I don't know the exact formula so please don't just use what I put as the answer.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by