image thumbnail
from orderseek - Finds chemical reaction order by Brad Ridder
Returns the reaction order, r-squared value, rate constant, and half life.

orderseek(t,C)
function data = orderseek(t,C)
%DATA = ORDERSEEK(T,C)
%Searches for the least-squares optimum solution for the reaction order
%from inputs time (t) and concentration (C). Outputs a struct (data) which
%contains the (1) reaction order (2) rate constant (3) rsquared value (4)
%half-life.
%t and C are vectors.
n = fminsearch(@(x) os_obj(t,C,x),0);
best_fit = polyfit(t,1./(C.^(n-1)),1);
k = best_fit(1)/(n-1);
rsquared = os_obj(t,C,n);
halflife = (2^(n-1) - 1)/...
           ((n-1)*k*C(1)^(n-1));
data.order = n;
data.k = k;
data.rsquared = -rsquared; %Revert back to positive value.
data.halflife = halflife;

function rsquared = os_obj(t,C,n)
%Order seek objective function. Returns the correlation coefficient for the
%line fit of the transformed data.
C_xform = 1./(C.^(n-1));
rsquared = -corr(t,C_xform).^2; %Negative, because we want the minimizer to maximize it.
%(c) February 8, 2010, Bradley James Ridder, University of South Florida.
%References:
%http://en.wikipedia.org/wiki/Rate_equation#Summary_for_reaction_orders_0.2C_1.2C_2_and_n

Contact us at files@mathworks.com