MATLAB: How to fit linear plateau equation

linear equationplateau condition

I want to fit linear equation with plateau condition.
y=a(x+n)+b
These are the data in which I Want to fit:
x=[0,80,100,120,150],
y=[1865,3608,4057,4343,4389]
I don not know how to find the plateau value of yield.

Best Answer

You can use this FEX file (BSFK)
The code is by default use QUADPROG from MATLAB, but can also work with QPAS project by Adrian Wills for user who has not access to optimization toolbox as showed below:
x=[0,40,80,100,120,150,170,200];
y=[1865,2855,3608,4057,4343,4389,4415,4478];
opt = struct('KnotRemoval','none','sigma',1,'qpengine','qpas');
pp = BSFK(x,y,2,2,[],opt);
% prepare graphical data
xi = linspace(min(x),max(x));
yi = ppval(pp,xi);
xb = pp.breaks(2);
yb = ppval(pp,xb);
clf
plot(x,y,'or',xi,yi,'-b');
xline(pp.breaks(2));
text(xb,yb,sprintf('(%g,%g)',xb,yb));