% Notebook to support Exercise 3.4.9, modeling a cooling potato.
% The data, in time/temperature pairs:

times = [0, 2, 4, 8, 10, 13, 17, 20, 24, 30];
temps = [204, 193, 184, 169, 162, 156, 149, 143, 138, 130];

% A plot:

plt1 = plot(times,temps,'-r');

% The temperature might be modeled by the function

syms u(t,k);
u(t,k) = 72 + 132*exp(-k*t)

% A least-squares function can be formed as

syms SS(k)
SS(k) = sum((u(times,k)-temps).^2);

% Now adjust k to minimize this.