%NLREG2g: Matlab script M-file for analyzing the 
%data stored in systemregressiondata
load systemregressiondata
%Define the error
f1 = @(p) p(1)*exp(-p(2)*x1) + p(3)*exp(p(4)*x2);
f2 = @(p) p(5)*exp(-p(2)*x1) + p(6)*exp(p(4)*x2);
w1 = std(y1);
w2 = std(y2);
E = @(p) norm(y1-f1(p))^2/w1^2 + norm(y2-f2(p))^2/w2^2;
%Minimize the error with fminsearch
%For initial guess, get orders correct
p0 = [.01 .1 .01 .1 1 1];
[p ssr]=fminsearch(E,p0) %Using p instead of pstar
q = 2*length(y1)-length(p0);
s = sqrt(ssr/q)
%
s1 = w1*s
s2 = w2*s