Effacer les filtres
Effacer les filtres

curvefitting using Fmincon is not accurate please help

2 vues (au cours des 30 derniers jours)
praveen
praveen le 1 Août 2017
Commenté : Mendi le 1 Août 2017
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 commentaires
praveen
praveen le 1 Août 2017
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.
Mendi
Mendi le 1 Août 2017
Try 'fit' function.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by