# How to extrapolate a plot?

194 views (last 30 days)
user1996 on 4 Jul 2016
Edited: David Goodmanson on 4 Nov 2022
How can I extrapolate the line so it begins in 0. A0=16.10 A2=7.50 Numbers: A1=[14.25 13.65 13.10 12.45 11.80 11.00 10.50 10.00 9.45 9.00 8.55 8.00] T=[180 360 420 480 540 780 1020 1200 1320 1380 1500 1740] C=log((A0-A1)./(A-A1))
plot(T,C,'*') After that I used polyfit function z=polyfit(T,C,1) And z1=polyval(z,T), and I plot it- plot(T,C,'*',T,z1). So the linear graph beging at same point as the T,C bu I want it to begin from 0, so how can I extrpolate the linear line?
##### 2 CommentsShowHide 1 older comment
user1996 on 6 Jul 2016
We did this on class so it was in the task.

John D'Errico on 4 Jul 2016
Edited: John D'Errico on 4 Jul 2016
Extrapolating this curve using anything other than a linear model is a foolish task. Even with a linear model, you are asking for a random result.
Worse, attempting to extrapolate the FIRST two points down to zero is absolute foolishness. Sorry, but it is. Given the apparent noise in your data, any prediction down at zero will be hugely uncertain from that.
plot(x,y)
axis(gca,[0,15,0,2000])
In fact, even that is a highly dangerous thing to do. You result will be virtually anything you want it to be.
Mark Twain says in Life on the Mississippi (1884):
“In the space of one hundred and seventy six years the Lower Mississippi has shortened itself two hundred and forty-two miles. That is an average of a trifle over a mile and a third per year. Therefore, any calm person, who is not blind or idiotic, can see that in the Old Oölitic Silurian Period, just a million years ago next November, the Lower Mississippi was upwards of one million three hundred thousand miles long, and stuck out over the Gulf of Mexico like a fishing-pole. And by the same token any person can see that seven hundred and forty-two years from now the Lower Mississippi will be only a mile and three-quarters long, and Cairo [Illinois] and New Orleans will have joined their streets together and be plodding comfortably along under a single mayor and a mutual board of aldermen. There is something fascinating about science. One gets such wholesale returns of conjecture out of such a trifling investment of fact.”
The above is my favorite quote about mathematics. It points out the dangers of long range extrapolation. Here, your data lives on the interval [8,14], so an interval of length 6, and you want to extrapolate all the way down to zero. This verges on something nearly as silly as what Mark Twain said.
So I'll use my own polyfitn tool to look at a linear model.
P = polyfitn(x,y,1)
P =
ModelTerms: [2x1 double]
Coefficients: [-245.52 3605.6]
ParameterVar: [168.62 20992]
ParameterStd: [12.985 144.89]
DoF: 10
p: [3.7142e-09 2.51e-10]
R2: 0.97279
RMSE: 81.601
VarNames: {'X1'}
Polyfitn is on the file exchange. Since you want to extrapolate down to x==0, the constant term is the estimate of the model at x==0, the y-intercept.
We can use the parameter standard deviation, plus or minus twice the standard deviation to see some confidence limits around that point.
P.Coefficients(2) + P.ParameterStd(2)*2*[-1 1]
ans =
3315.8 3895.4
So plot it all together.
xev = 0:14;
yev = polyvaln(P,xev);
plot(x,y,'go',xev,yev,'-b',[0 0],P.Coefficients(2) + P.ParameterStd(2)*2*[-1 1]','rs')
The red squares are estimates of the uncertainty (roughly a 95% interval) around the point at zero, based on a fit from the entire curve. I would hardly trust that extrapolation down that far even with this simple linear model.
##### 2 CommentsShowHide 1 older comment
Stephen23 on 6 Jul 2016
+1 the Mark Twain quote is brilliant.

David Goodmanson on 4 Nov 2022
Edited: David Goodmanson on 4 Nov 2022
What is being fitted is T vs. C, with the idea of extrapolating to T=0.
The C variable,
C=log((A0-A1)./(A-A1))
contains A, which has not been defined. Also, A2 has not been used. So if what was intended is (A2-A1), (and reversing it to keep a positive argument to the log), the result is shown on the plot. For an extrapolation, this seems reasonable. The added domain is about 12% of the original domain.
A0 = 16.10;
A2 = 7.50;
A1 = [14.25 13.65 13.10 12.45 11.80 11.00 10.50 10.00 9.45 9.00 8.55 8.00];
T = [180 360 420 480 540 780 1020 1200 1320 1380 1500 1740]
C = log((A0-A1)./(A1-A2))
p = polyfit(T,C,1)
Cfit = polyval(p,T);
Cfit0 = polyval(p,0)
figure(1)
plot(T,C,T,Cfit,0,Cfit0,'ok')
grid on
Cfit0 = -1.6067 % quoting -1.6 seems appropriate under the circumstances
z