How to fit quadratic function with plateau condition, where the plateau condition is achieved by linear fit?

조회 수: 1 (최근 30일)
The values of x and y are as follows:
x=[0,80,100,120,150],
y=[1865,3608,4057,4343,4389]
My equations are as follows:
y=a(x)^2+b(x)+c, x < xc(Ymax) ....(1)
y=yp, x >= xc(Ymax) ....(2)
I want to fit these two equations, where first equation will provide a quadratic fit whereas the second equation will provide a linear one. The problem is when we are trying to fit, it provide us best fit in quadratic form (eq.1), it did not include the linear fit (eq.2).
We are also providing the code that we have used:
yf = @(b,x) b(1).*x.^2+b(2)*x+b(3);
B0 = [0.006; 21; 1878];
[Bm,normresm] = fminsearch(@(b) norm(y - yf(b,x)), B0);
a=Bm(1);
b=Bm(2);
c=Bm(3);
xc=-b/(2*a);
p=c-(b^2/(4*a));
if (x < xc)
yfit = a.*x.^2+ b*x+c;
else yfit = p;
end
plot(x,yfit, '*')
hold on
plot(x,y)
hold off
We are providing the graph (fig(1)) which we got from our results. For further understanding, we are also proving a graph (fig(2)) which shows how the result should come.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by