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 commentaires

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.

Connectez-vous pour commenter.

 Réponse acceptée

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 commentaires

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur General Applications dans Centre d'aide et File Exchange

Produits

Version

R2018a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by