
How to fit quadratic function with plateau condition?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
madhuri dubey
le 23 Juil 2018
Commenté : Srishti Vishwakarma
le 16 Jan 2019
I want to fit quadratic function with plateau condition
(y=a(x+n)^2+b(x+n)+c, x < xc(Ymax) ;
y=yp, x >= xc(Ymax).
Where a,b,c & n are constants, and xc is critical value at which y is maximum. My data is x=[0,80,100,120,150], y=[1865,3608,4057,4343,4389].
0 commentaires
Réponse acceptée
Matt J
le 23 Juil 2018
Modifié(e) : Matt J
le 23 Juil 2018
LSQCURVEFIT seems to do a decent job. There was no guarantee that it would work - it's not clear to me that the model function has a well-defined Jacobian.
x=[0,80,100,120,150],
y=[1865,3608,4057,4343,4389]
p0=[0,polyfit(x,y,1)];
[p,resnorm,residual,exitflag,output] = lsqcurvefit(@F,p0, x,y,[],[0,inf,inf]);
a=p(1);
b=p(2);
c=p(3);
n=0; %redundant parameter
plot(x,y,'--*',x,polyval(p,x),'-');
xlabel 'x'
ylabel 'y'
function fval=F(p,xdata)
[a,b,c]=deal(p(1), p(2), p(3));
xc=-b/2/a;
if ~isfinite(xc),
xc=inf;
yp=inf;
else
yp=polyval(p,xc);
end
fval=polyval(p,xdata);
fval(xdata>xc)=yp;
end

6 commentaires
Matt J
le 23 Juil 2018
Because Matlab cannot recognize the function F(). You pasted it somewhere that makes it invisible.
Plus de réponses (2)
Voir également
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!