Global fit over several variables with one function respectively for shared parameters
4 views (last 30 days)
Show older comments
Hello,
I have data for 5 different variables L1,L2,U,I,N (ydata) according to some xdata. Each of them can be calculated by a function and all these functions share up to 6 parameters. Now I want to do a global fit for all my data to calculate the parameters. I tried a lot like this:
function x = fUn0o2( M )
% output: [mUI;mIU;mIN;mNI;kIU(0);kNI(0)]
% input: [xdata,ydata] (nx6-Mat)
xdata = M(:,1);
ydata = M(:,2:6);
xdata = xdata';
ydata = ydata';
x0 = [-2;0;-2;0;0;0.5];
options = optimset('MaxFunEvals',1e10,'MaxIter',1e3);
[x,resnorm] = lsqcurvefit(@fUnktIoN0o2,x0,xdata,ydata,[],[],options);
function L = fUnktIoN0o2( x,xdata )
% UIN; input: 6x1-Mat, output: lambda1,lambda2,U,I,N
kUI = 19.1.*exp(x(1).*xdata);
kIU = x(5).*exp(x(2).*xdata);
kIN = 203.6.*exp(x(3).*xdata);
kNI = x(6).*exp(x(4).*xdata);
S = kUI + kIU + kIN + kNI;
L1 = 0.5.*(S+((S.^2)-4.*(kIU.*kNI + kUI.*kNI + kUI.*kIN)).^0.5);
L2 = 0.5.*(S-((S.^2)-4.*(kIU.*kNI + kUI.*kNI + kUI.*kIN)).^0.5);
I = 1./(((kIN)./(kNI))+((kIU)./(kUI))+1);
U = ((kIU)./(kUI)).*I;
N = ((kIN)./(kNI)).*I;
L = [L1;L2;U;I;N];
end
I hope it is understandable, what I tried to do here, though it is a long text and not exactly clearly arranged. My main problem is, that by adding more formulas and data to my program to make my fit more accurate, I accomplish exactly the opposite and my fit gets worse and worse, so I hope someone can help me finding my mistake(s).
Thank you in advance,
Alex
0 Comments
Accepted Answer
Matt J
on 5 Nov 2013
Edited: Matt J
on 5 Nov 2013
Nobody can troubleshoot your code without some way to run and reproduce the problems you're seeing.
Just as a guess, though, the ydata quantities L1 and L2 (the roots of some quadratic?) are not differentiable functions of the x(i) parameters, unless you impose a constraint that the discriminant
(S.^2)-4.*(kIU.*kNI + kUI.*kNI + kUI.*kIN)>= lb > 0
where lb is some strictly positive lower bound. For constraints like that, you would need fmincon.
Further, even if you used fmincon to do this, it is not clear to me that such a constrained region is contiguous over the space of x. You might need a very good initial guess to converge to the right region.
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!