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

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

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?
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

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.
I used what you did earlier and it seemed to work just fine, i get very realisitic results

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 General Applications에 대해 자세히 알아보기

제품

릴리스

R2018a

태그

질문:

2019년 8월 6일

댓글:

2019년 8월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by