FMINCON Curve fitting
古いコメントを表示
I am trying to use FMINCON to solve for the parameters in a model with two inputs and four unknown parameters. I would like FMINCON to find the set of parameters that minimize the squared residuals of the model predictions to what I have measured. This is analogous to using EXCEL SOLVER to do curve fitting. The model is nonlinear with unknown parameters P and of the form:
F(X,Y) = P1*P2^(X/10)-(P3*P4*Y/(P4+P3*Y)
Does anyone know how to do this? I am lost.
回答 (1 件)
Sean de Wolski
2014 年 10 月 13 日
編集済み: Sean de Wolski
2014 年 10 月 14 日
fmincon is overkill. Use lsqcurvefit which already has the objective function framed for you.
doc lsqcurvefit % for more info
MORE
Here's a full example:
% Something to simulat data
P1act = pi;
P2act = 1;
P3act = exp(1);
P4act = 0.06;
X = rand(100,2); % Simulate X, first column is your "X", second is your "Y"
zz = P1act*P2act.^(X(:,1)/10)-(P3act*P4act.*X(:,2)./(P4act+P3act.*X(:,2)));
% Use the solver
fun = @(P,x)P(1).*P(2).^(x(:,1)/10)-(P(3)*P(4).*x(:,2)./(P(4)+P(3).*x(:,2)));
x0 = [2 1 2 0.1];
p = lsqcurvefit(fun,x0,X,zz)
5 件のコメント
Matt J
2014 年 10 月 13 日
... unless you have complicated constraints that you haven't mentioned...
Adrian
2014 年 10 月 14 日
Sean de Wolski
2014 年 10 月 14 日
See MORE for a full example
xdata is an mxd matrix where d is the number of dimensions, in this case two. So xdata should be your [x, y]
xdata = [X Y]
Ydata is the independent variable (i.e. Z).
Above, I simulated some xdata and ydata and rewrote the function the way the solver expects it. The first input are the coefficients that are being searched for, the second is the xdata.
Hany Ferdinando
2018 年 11 月 28 日
I also used fmincon for curve fitting problem because I have several linear constraints between the parameters. For examples, x(1) < x(2) < x(3). Is there any way to add such constraints in lsqcurvefit? I saw there is no way to use upper and lower bounds for these constraints. Thanks!
Torsten
2018 年 11 月 28 日
Instead of using x(1),x(2),x(3),... use y(1)=x(1), y(2)=x(2)-x(1), y(3)=x(3)-x(2),... as solution parameters and put constraints y(2) >=0, y(3) >= 0,...
Best wishes
Torsten.
カテゴリ
ヘルプ センター および File Exchange で Choose a Solver についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!