FMINCON Curve fitting
23 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Sean de Wolski
on 13 Oct 2014
Edited: Sean de Wolski
on 14 Oct 2014
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 Comments
Hany Ferdinando
on 28 Nov 2018
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
on 28 Nov 2018
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.
See Also
Categories
Find more on Nonlinear Optimization 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!