# Write a script to determine the change in temperature of the liquid over a 200 minute time period using the following equation: T(i+1)=T(i​)+K*(Delta​_t)*(F-T(i​))

1 view (last 30 days)
Kyle on 26 Oct 2022
Commented: William Rose on 26 Oct 2022
The start Temperature of a liquid is 50 and is placed into a fridge of temperatue 5. (F=5)
Have to calculate each value of T(i+1) from the value of ܶT(i) from the previous time step over a space of 200 minutes where the time in dived into time steps each of duration delta_t. Must be computed using a 'For' loop. Also K = 0.045
I cant seem to get the time incrments correct as i always get negative values for my temperature which doesnt make any sense realistically.
clear all
clc
F=5
K=0.045
for x=200:-20:0
T=50:-5:5
T_final=T+K*x*(F-T)
end
plot(x,T_final)
Kyle on 26 Oct 2022
Any help would be much appreciated as i feel i have exhausted my knowledge

William Rose on 26 Oct 2022
The change in temperature in each time step is proportional to the difference bwteeen the current temp and the fridge temp (Tf=5, constant):
deltaT = K*(T-Tf)*deltat
where deltaT is the change in temp (it changes with each time step) and deltat is the time step size (constant). I have assumed that K is a "rate of decay" constant, with units of 1/time.
You get negative values because you assume the temperature just declines at a constant rate, instead of assuming that it decays at a rate proportional to the difference between current tmp and fridge temp.
You can put that idea into a Matlab script.
By the way, this problem also has an analytical solution, involving an exponential function:
T(t)=(Tinit-Tf)*exp(-Kt) + Tf
If you plug in t=0 and t=infinity, you see that T(0)=Tinit=50 and T(infinity)=Tf=5, which makes sense.
##### 2 CommentsShowHide 1 older comment
William Rose on 26 Oct 2022
@Kyle, you're welcome and good luck.