MATLAB Answers

How to extrapolate data from a matrix of x axis values and corresponding y axis values?

조회 수: 40(최근 30일)
somnath
somnath 2014년 5월 11일
답변: Star Strider 2014년 5월 11일
let x axis values be x=[.1 . 2 . 3 . 4 . 5 . 6 . 7 . 8 . 9 1.7 1.8 1.9 2] and corresponding y axis values be y=[50 65 70 80 90 100 110 120 150 180 220 295 400 ];
I want to find value of y corresponding to x = 4
  댓글 수: 2

댓글을 달려면 로그인하십시오.

답변(3개)

Image Analyst
Image Analyst 2014년 5월 11일
편집: Image Analyst 2014년 5월 11일
To extrapolate you must assume some kind of function, like a line or quadratic or something. Maybe you can use polyfit:
x=[.1 .2 .3 .4 .5 .6 .7 .8 .9 1.7 1.8 1.9 2]
y=[50 65 70 80 90 100 110 120 150 180 220 295 400 580 1000 2400 5000 8900 15000 24000];
plot(x, y(1:13), 'bd-', 'MarkerSize', 10)
coeffs = polyfit(x, y(1:13), 2);
xfit = linspace(x(1), x(end), 50);
yfit = polyval(coeffs, xfit);
hold on;
plot(xfit, yfit, 'ro-', 'LineWidth', 2);
grid on;
% Get value for x = 4:
yfit4 = polyval(coeffs, 4)
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
By the way, why does y have 20 elements and x have only 13?

lvn
lvn 2014년 5월 11일
This is for a linear extrapolation:
interp1(x,y,4,'linear','extrap')
ans =
2.5000e+03

Star Strider
Star Strider 2014년 5월 11일
The data are so discontinuous that extrapolating them is almost absurd. However a 5-th degree polynomial gives the best fit to the data:
x = [.1 .2 .3 .4 .5 .6 .7 .8 .9 1.7 1.8 1.9 2];
y = [50 65 70 80 90 100 110 120 150 180 220 295 400 ];
[p,S,mu] = polyfit(x,y,5);
xe = linspace(min(x),4);
[ye,dlta] = polyval(p,xe,S,mu);
figure(1)
plot(x,y, '*')
hold on
plot(xe,ye,'-b', xe,ye+dlta,'-r', xe,ye-dlta,'-r')
hold off
% axis([0 3 0 500])
grid
fprintf(1,'\n\tExtrapolated value at x = 4 is %.4f ± %.4f\n\n', ye(end), dlta(end))
and produces:
Extrapolated value at x = 4 is 74066.6051 ± 13925.4417
Which considering its original exponential behaviour (with the 20-element y-vector), is entirely consistent.
This definitely shows the dangers of extrapolating so far from the region-of-fit with discontinuous data and a poorly-characterised function. A large number of functions will ‘fit’ to it, generating a large number of different extrapolations, and since we have no idea what the function actually does outside the region-of-fit (if it does anything; it may not be defined beyond the data given), they are all entirely wild guesses and all entirely without any valid mathematical or statistical support.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by