function y=linfit(k) %This function takes in the values of ka and kb %from the non-linear optimization routine and %computes the best fit values for the linear %fitting parameters A and B. The function returns %the sum of the square of the deviation which %we are trying to minimize. We make use of the %global command between this function and the %main script so that we can pass the best fit %values of A and B back and forth, and also pass %in the data values. The latter is done to minimize %the data I/O. % %Thus: global tpass cpass capass cbpass clear a t=tpass; c=cpass; a=[exp(k(1)*t),exp(k(2)*t)]; x=a\c; capass=x(1); cbpass=x(2); y=norm(a*x-c)^2;