Fit a function to the given data y(x) and extrapolate for y(0)

55 Ansichten (letzte 30 Tage)
Taimoor Khan Mehmand
Taimoor Khan Mehmand am 2 Okt. 2020
Bearbeitet: John D'Errico am 2 Okt. 2020
I want to fit a function to the given data y(x) and extrapolate for y(o). Can anybody help?
Here is the code:
clear all
close all
clc
x = [3.0000 3.2143 3.4286 3.6429 3.8571 4.0714 4.2857 4.5000 4.7143 4.9286 5.1429 5.3571 5.5714 5.7857 6.0000];
y = [1.4463 1.4009 1.3602 1.3236 1.2907 1.2612 1.2346 1.2108 1.1894 1.1701 1.1529 1.1373 1.1234 1.1108 1.0996];
figure,
plot(x, y, 'x')
xlabel('{\itx}', 'FontSize', 14)
ylabel('{\ity}', 'FontSize', 14)
grid on

Antworten (1)

John D'Errico
John D'Errico am 2 Okt. 2020
Bearbeitet: John D'Errico am 2 Okt. 2020
This is a LONG way to extrapolate. (Need I post, yet again, the Mark Twain quote about the dangers of extrapolation?)
The point is, your data spans from 1.45 in y, down to 1.1. And you want to predict the point where y will be zero?
You are effectively asking to extrapolate roughly 200% of the range of your data.
“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.”
Mark Twain, in Life on the Mississippi (1884)
The point is, extrapolation of ANYTHING over a long of a distance is likely to result in completely random, meaningless predictions. And that is what you want to do here. Even though the data is pretty good, that much extrapolation is going to be virtually random. You can get any answer you wish to see.
plot(x,y,'o')
axis([3 25 0 1.5])
Now, you are asking to predict where that curve will cross at y == 0. Seriously?????
Even though your data is reasonably good, you have relatively little of it. And worse, you have ABSOLUTELY NO MODEL. That is, you seem to have no clue as to what a model for this process would be.
I'm sorry, but asking to predict where that curve crosses zero is a blatant misuse of mathematics and statistics, pure and simple. (Yes, this may seem cruel, but it is the truth.) If someone does show you how to predict that point, then ask them to provide confidence bands on where it does cross. Ask them if those bands are dependent on knowing the model, since you have provided no model.
I know. You don't believe me. Nice smooth data like that.
mdl = fit(x',y','poly3')
mdl =
Linear model Poly3:
mdl(x) = p1*x^3 + p2*x^2 + p3*x + p4
Coefficients (with 95% confidence bounds):
p1 = -0.004551 (-0.004849, -0.004253)
p2 = 0.08901 (0.08499, 0.09304)
p3 = -0.6299 (-0.6477, -0.6122)
p4 = 2.657 (2.632, 2.683)
plot(mdl)
hold on
plot(x,y,'o')
That fit seems quite good. Where does it cross zero?
yline(0,'g');
hold on
plot(mdl)
plot(x,y,'o')
xpred = linspace(3,15,100);
ypred = mdl(xpred);
yint = predint(mdl,xpred);
plot(xpred,ypred,'r-')
plot(xpred,yint,'m-')
axis([3 15 -3 1.5])
So this curve, which fit the data quite nicely, predicts the curve crosses the axis around 12 or so. But I doubt you would believe that result, because the curve has an unexpected unflection point. So even though the data never shows a downturn like the model, the model predicts this strange behavior.
Of course, I might have tried a different model. In fact, it looks as if an exponential model fits the data just as well as the polynomial model did.
ft = fittype('a + b*exp(-c*x)','indep','x')
ft =
General model:
ft(a,b,c,x) = a + b*exp(-c*x)
>> mdl = fit(x',y',ft)
Warning: Start point not provided, choosing random start point.
> In curvefit.attention/Warning/throw (line 30)
In fit>iFit (line 307)
In fit (line 116)
mdl =
General model:
mdl(x) = a + b*exp(-c*x)
Coefficients (with 95% confidence bounds):
a = 1 (0.9999, 1)
b = 2.001 (1.999, 2.003)
c = 0.5002 (0.4997, 0.5006)
Hmm. So it looks like the model
y = 1 + 2*exp(-0.5*x)
fits the data quite well. So well, in fact, that the parameters eem alosmot exact, so this is surely made up data.
Of course, you should then realize that model NEVER crosses the line y==0. So asking for the point where that happens is just as meaningless as any other result.

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by