- #1
roam
- 1,271
- 12
I'm very confused on about solving the following question using Matlab:
A drink cools according to the difference equation:
Tn=Tn-1-0.02(Tn-1-Ta)
Where Tn is the temprature after n minutes. When you pour the drink it's 80 degrees. After you have poured it you leave it for 15 minutes in the kitchen where the air temprature is 20 degree, then you take it outside where the temprature is 12 degrees. Calculate the temprature of the drink afte it has been outside for 15 minutes.
This is my script:
I'm not quite sure what I've done wrong here but I keep getting errors like:
Any guidance is greatly appreciated.
A drink cools according to the difference equation:
Tn=Tn-1-0.02(Tn-1-Ta)
Where Tn is the temprature after n minutes. When you pour the drink it's 80 degrees. After you have poured it you leave it for 15 minutes in the kitchen where the air temprature is 20 degree, then you take it outside where the temprature is 12 degrees. Calculate the temprature of the drink afte it has been outside for 15 minutes.
This is my script:
Code:
k=0.02;
T_a=12;
S(1)=80;
S_a=20
for n=1:15
S(n+1)=S(n)-k(S(n)-S_a);
T(1)=S(16);
T(n+1)=T(n)-k(T(n)-T_a);
end
T(16)
I'm not quite sure what I've done wrong here but I keep getting errors like:
S_a =
20
? Attempted to access k(60); index out of bounds because numel(k)=1.
Error in ==> temp at 6
S(n+1)=S(n)-k(S(n)-S_a);
Any guidance is greatly appreciated.