%% Decomposition of H2O2
%% Kurt Bryan and SIMIODE
%
% This is a Matlab script to analyze H2O2 decomposition data.
%
% The times at which concentration data was taken are

times = [0,120,300,600,1200,1800,2400,3000,3600];

% The concentration data (moles per liter) is

data = [1.00,0.91,0.78,0.59,0.37,0.22,0.13,0.08,0.05];

% Compute the number of data points

N = length(data);

% and perform a logarithmic transformation of the data

log_of_data = log(data);

% A plot of the log-transformed data:

figure(1);
plot(times,log_of_data,'.r','MarkerSize',20)

% Fit a line (degree 1 polynomial) of the form y = c(1)*times + c(0) to the data

c = polyfit(times,log_of_data,1)

% Evaluate line at each time, superimpose a graph of the line on a plot with the log data

figure(2)
plot(times,log_of_data,'.r','MarkerSize',20)
fittimes = polyval(c,times);
hold on
plot(times,fittimes,'-b');
xlabel("Time (seconds)");
ylabel("log(concentration) (moles/liter)");
hold off