How to fit quadratic function with plateau condition, where the plateau condition is achieved by linear fit?
3 次查看(过去 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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filter Banks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!