Extrapolate using half the slope than in original data
3 views (last 30 days)
I have a set of 21 X,Y poinst which I intend to extrapolate by using slope (rate of change)= 1/2 than that is observed in the original X,Y dataset.
The code thus far
Xext=22:82; (trying to extrapolate until limit= 82)
c = polyfit((X(end-8:end)), (Y(end-8:end)),1); % linear fit based on the last 8 points
c1=[c(1)/2, c(2)];%%making slope 1/2 of the original X,Y dataset
Yext = polyval(c1,Xext);
%%plotting to obtain a figure that shows the first 21 points changing at the observed rate and the next extrapolated to change at 1/2 its rate
This makes a bit of an unwated hump where the extrapolation begins (see attached)
Any help is greatly appreciated
dpb on 27 Jun 2020
You've got to match the two at the breakpoint...w/o data so didn't use but the endpoints to roughly match your figure...
x=[1 20]; y=[695 420]; % about what the fitted line looks to be
b1=polyfit(x,y,1); % first section coefficients
b2=[b1(1)/2 polyval(b1,x(end))-b1(1)/2*x(end)]; % solve for intercept to match at breakpoint x
Above yields for a set of data after the breakpoint as well as before...
plot(x,polyval(b1,x),'b-', ... % first segment uses b1 coefficients while
[0 80]+x(end),polyval(b2,[0 80]+x(end)),'r-') % at/after uses second
NB: the endpoints match this way.
NB SECOND: Above uses x from origin for both sections and requires using the proper coefficient array for the two sections. Alternatively, one could use a new origin at the end of first segment depending on the application. Slope would be same but the intercept for second would then be yfit(x(end)).