% listing of the file "kin3F.m" used by file "kin3.m" % Define the relationship between the value q (see last line) % and kin3F and the initial guess vector g. % These are all arbitrary names. % The value of q is what fminsearch minimizes. function q = kin3F(g); % declare global variables used by kin3.m and kin3F.m global rexp cA cB % pull kf, kr, KA, KB out of the parameter value guess vector g kf = g(1); kr = g(2); KA = g(3); KB = g(4); % compute the "calculated" rate, rcalc % dot . needed before / since numerator and denominator are % matrices and you don't want matrix division, just % division of individual elements in the matrices % dot . NOT needed before the * here since k, KA, KB are scalars rcalc = (kf * cA - kr * cB) ./ (1 + KA * cA + KB * cB); error = (rexp - rcalc); q = sum(error .^ 2);