#A helpful script for Exercise 3.4.2.

#Here is the data for Exercise 3.4.2
data = [[0, 1.0], [300, 0.78], [1200, 0.37], [3000, 0.08]];
N = len(data);

#However, we will work with the log of the concentration, so form
logdata = [[data[i][0],log(data[i][1])] for i in range(N)];

#A plot:
plt1 = scatter_plot(logdata);
show(plt1)

#aTo fit a function u(k,t) = k*t to this data by adjusting "k", define
var('t k');
u(t,k) = k*t; #The model function to fit
SS = function('SS')(k);
SS(k) = add((u(logdata[i][0],k)-logdata[i][1])^2 for i in range(N));

#Now minimize SS(k) with respect to k.