function y=delta(guess) %This function takes in guesses for the unknown parameters n, ln(k0) and %E/RTr, and returns the deviation between the model and the data. We bring %the data in through the "global" command: global crpass cr0pass Tpass Tr=298; %The reference temperature. qr=0.1; %The flow rate (liters/min) m=1; %The amount of catalyst (g) n=guess(1); %The first parameter k0=exp(guess(2)); %The second parameter ERTr=guess(3); %The third parameter miss=crpass-cr0pass+m/qr*crpass.^n*k0.*(Tr./Tpass).^n.*exp(-ERTr*Tr./Tpass); %OK, the question is how to weight each of the data points. As it is %currently written, it tends to accentuate the weighting at higher %temperatures where the conversion is the largest. This is because cr is %lowest, and it is multiplied by a large value to make it balance cr0. It %also places a stronger weight on the runs with higher intial %concentrations. On the other hand, for lower cr we should have more %accurate measurements (if the fractional error is fixed, for example). %Different weightings will yield different "solutions" for optimal parameters. %A reasonable choice is to weight each of the runs with the inverse of the %initial concentration. This is essentially equivalent to assuming an error %proportional to the concentration measured, and each data point should be %of O(1). Thus: miss=miss./cr0pass; %and thus we get the objective function: y=sum(miss.*miss);