I am trying to model two vector data sets f1(x) and f2(x) using two non-linear equations with common variables.
f1(x) = a0 + a1(k1,t)*exp(-l1*x) + a2(k1,t)*exp(-l2*x) f2(x) = b0 + b1(k1,t)*exp(-l1*x) + b2(k1,t)*exp(-l2*x)
I would like to simultaneously fit f1(x) and f2(x) to these two equations. Then graphically display the data and fits. The a1, a2, b1, and b2 are expressions which are different but contain the variables k1 and t which will be determined from the simultaneous fit. I would like to use matlab script to do this.
Is fsolve the way to do this? If so, can somebody please give a little direction as to setting this up?
Edit: I have been trying fmincon, but need the minimization to output a global minimum for the vector data sets, not a minimum at each point. Is there a way around this in simple code?
No products are associated with this question.
You can treat this as a least-squares problem with 6 parameters: a0, b0, k1, t, l1, and l2. Then make your objective function the total square error ((y1 - f1(x))^2 + (y2 - f2(x))^2). So something like
function err = myerrorfun(c,x1,y1,x2,y2) f1 = c(1) + [function of c(3) and c(4)]*exp(-c(5)*x1) + ...; f2 = c(2) + [function of c(3) and c(4)]*exp(-c(5)*x2) + ...; err = (y1-f1).^2 + (y2-f2).^2;
Then in your main program, call a minimization routine like fmincon:
x1 = ... % enter/load x2 = ... % all y1 = ... % the y2 = ... % data
% make a function handle of one variable (the parameters), with the data embedded objective = @(c) myerrorfun(c,x1,y1,x2,y2); % do the fitting c_fit = fmincon(objective,...);