% Notebook to support Exercise 3.4.11, 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');

% We seek to a function u(t) of the form

A = 72;
u0 = 204;
syms u(t,k,r);
u(t,k,r) = A + ((u0-A)^(1-r) + k*(r-1)*t)^(1/(1-r))

% A least-squares function can be formed as

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

% Now adjust k and r to minimize this

fsurf(log(SS(k,r)),[0 0.0004 2 2.5])