How to fit quadratic function with plateau condition?

조회 수: 3 (최근 30일)
madhuri dubey
madhuri dubey 2018년 7월 23일
댓글: Srishti Vishwakarma 2019년 1월 16일
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].

채택된 답변

Matt J
Matt J 2018년 7월 23일
편집: Matt J 2018년 7월 23일
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
madhuri dubey
madhuri dubey 2018년 7월 23일
편집: Matt J 2018년 7월 23일
Ok forget about p0. My question is when I have just copied and pasted your code then what is the problem. Why have I got this error?
Undefined function or variable 'F'.
Error in lsqcurvefit (line 202)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Matt J
Matt J 2018년 7월 23일
Because Matlab cannot recognize the function F(). You pasted it somewhere that makes it invisible.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

madhuri dubey
madhuri dubey 2018년 7월 24일
I have some doubt related to your code, which you have sent me at first. In my question, I have mentioned that I want to fit quadratic plus plateau. But in your solution graph showed that one curve fit line (red) and another one (blue) is just join the observed data point. Where is the plateau line? Or what is the value of ymax. I have attached one document, I hope it will clear what I want to ask. Kindly see Fig. 1(b) and equation (3) and (4).

madhuri dubey
madhuri dubey 2018년 7월 24일
Sorry, I forget to attach the file.

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by