curvefitting using Fmincon is not accurate please help

2 次查看(过去 30 天)
I have used the fmincon to do curve fitting and here is the below code :
'y ranges between 0.02 please see figure'
xdata =t;% t renges from 0 to 3000
pot_diff = abs(max(y) - min(y));
F = @(x) sum((x(1)*(exp(-xdata/x(2)))+(pot_diff-x(1))*(exp(-xdata/x(3)))-y).^2);
% F = @(x) sqrt(mean(((x(1)*(exp(-xdata/x(2)))+(pot_diff-x(1))*(exp(-xdata/x(3)))-y).^2)));
x0 = [0.01 2000 1000];
A = [];
b = [];
Aeq = [];
beq = [];
% lb = [0 0 0 ];
% ub =[0.6*pot_diff inf inf ];
lb = [0.2*pot_diff 4000 1000];
ub =[0.6*pot_diff 10000 7000];
options = optimoptions('fmincon');
options = optimoptions(options,'Display', 'off');
options = optimoptions(options,'MaxFunEvals', 10000);
options = optimoptions(options,'MaxIter', 30000);
options = optimoptions(options,'TolFun', 1e-10);
options = optimoptions(options,'TolX', 1e-6);
options = optimoptions(options,'TolCon', 1e-6);
options = optimoptions(options,'Algorithm', 'interior-point');
options = optimoptions(options,'FinDiffType', 'central');
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(F,x0,A,b,Aeq,beq,lb,ub,@my_nlincon,options);
D = @(x,xdat) x(1)*(exp(-xdata/x(2)))+(pot_diff-x(1))*(exp(-xdata/x(3)));
xdat = matname(Tstart:endT);
xdat = (xdat-xdat(1))';
y_p = D(x,xdat);
%%%%%%%%%%%%%%%
function [C,Ceq] = my_nlincon(x)
pot_diff =evalin('base','pot_diff');
% C(1) = x(1)-x(3);
C = x(3)-x(2);
% Ceq =x(3)+x(1);
Ceq =[];
return
The problem now is the estimated parameters fall in expected boundary but the curve fit is not so good. Please help me if any modification to my logic is required. I already tried lsqcurvefit but it just did not work because of boundary constraints.
  3 个评论
praveen
praveen 2017-8-1
Actually i am trying to minimize the difference (error) between the estimated value and the predicted value by subtracting and squaring the each obtained estimated points and the sum of all the error (different approach for least square)should be minimum so that i can find minimum point(using fmincon) and also the estimated points should fall in my boundary. Hope this helps in better understanding.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by