constrained fitting using lsqcurvefit / fmincon

1 回表示 (過去 30 日間)
Art
Art 2012 年 11 月 29 日
I have a set of data points (data_x, data_y). I need to fit a model function into this data. Model is a function of 5 parameters, and I have defined it like that:
function F = model(x,xdata)
fraction1 = x(4);
fraction2 = x(5);
fraction3 = 1-x(4)-x(5);
F=1-(fraction1.*(exp(-abs(xdata)./x(1)))+(fraction2.*(exp(-abs(xdata)./x(2))))+(fraction3.*(exp(-abs(xdata)./x(3)))));
parameters x(4) and x(5) are used to define three fractions (as %), so their sum MUST be 1. To fit this curve I was using lsqcurvefit, like that:
%%initial conditions
a0 = [guess1 guess2 guess3 0.3 0.3];
%%bounds
lb = [0 0 0 0 0 ];
ub = [inf inf inf 1 1];
%%Fitting options
curvefitoptions = optimset( 'Display', 'iter' );
%%Fit
a = lsqcurvefit(@model,a0,x,y,lb,ub,curvefitoptions);
The thing is that don't know how to add constraints, to keep the sum of fractions = 1. I know that lsqcurvefit is not the best solution for this problem, but I have no idea how to feed fmincon with these data to finally find my parameters. Many thanks for help!

回答 (1 件)

Alan Weiss
Alan Weiss 2012 年 11 月 29 日
fmincon can satisfy your conditions, which are, I believe:
0 <= x(4) <= 1
0 <= x(5) <= 1
0 <= 1 - x(4) - x(5) <= 1, which, when combined with the previous, is the same as
x(4) + x(5) <= 1
Create the following bounds and matrices:
lb = zeros(5,1);
ub = [inf;inf;inf;1;1];
A = [0,0,0,1,1]; % for Ax <= b
b = 1; % for Ax <= b
After you put xdata and ydata in your workspace, your objective function can be
@(x)sum((model(x,xdata) - ydata).^2)
Use a reasonable fmincon algorithm, such as interior-point or sqp.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by