I am trying to work on my assignment, but I am having some trouble, the problem statement is:

Use Euler's method, and assume a cooling constant r = 0.2 , initial temperature of 86 C, and room temperature at 17 C. Choose your time

step h judiciously and integrate to 5 minutes.

__You can add some cream which will drop the temperature instantly by 5 C__.

(a) Now, add the cream at the beginning. Plot your results. What is the temperature after 5 min?

(b) Add the cream at the end. Plot the results (preferably on the same figure). What is the temperature at the end?

I started the program in matlab:

Code:

clc
clear all
r=0.2; %Cooling Constant
T=86 ; % Initial Temperature
t=0 ;
Ts=17; %Surrounding Temperature
h=0.1 ; %Step Size
nsteps=300 ;
for i=0:nsteps
fprintf('%0.2f %0.3f\n',t,T)
dT=-r*h*(T-Ts) ;
T=T+dT ;
t=t+h;
end
plot(t,T)
xlabel('Time (Sec)');
ylabel('Temperature (C)');
grid;

the problem is the plot only plots the last value in the loop, I tried to store it in an array, but I kept getting an error?