Am I using extrap wrong?

17 visualizzazioni (ultimi 30 giorni)
Danielle
Danielle il 7 Nov 2014
Commentato: Star Strider il 7 Nov 2014
I'm trying to get extrap in linear, cubic, and spline methods. I have:
x = linspace(0, 4*pi) y = sin(x) c = 'yrbgk' ax = [0, 14, -2, 2]
axis(ax)
l = length(x)
o = l ./ 5
t = (2.*l)./5
th = (3.*l)./5
f = (4.*l)./5
fi = (5.*l)./5
cc = c(1)
cd = c(2)
ce = c(3)
cf = c(4)
cg = c(5)
omg = x(1:o)
zomg = x(1:t)
golly = x(1:th)
gee = x(1:f)
goshers = x(1:fi)
% all five pieces of data and colors
%first extrap
subplot(3,1,1)
yout = interp1(x, y, omg, 'linear', 'extrap')
youtu = interp1(x, y, zomg, 'linear', 'extrap')
youtub = interp1(x, y, golly, 'linear', 'extrap')
youtube = interp1(x, y, gee, 'linear', 'extrap')
plot(goshers,y,cg,gee,youtube,cf,golly,youtub,ce,zomg,youtu,cd,omg,yout,cc)
xlabel('x values')
ylabel('y values')
title('Interp1: Linear') My answer is supposed to look like this:
but mine looks like the black function with the color changing by range of x value. From 0 to 2 it is yellow, from 2 to 4 it is red, 4 to 6 is blue, 6 to 8 is green and 8 to 10 is black

Risposta accettata

Star Strider
Star Strider il 7 Nov 2014
That’s how extrapolation works. The extrapolation routines do their best to guess what your data are doing a few samples beyond what is known. The more data you give them, the more accurate the extrapolation is.
As a general rule, don’t extrapolate more than a few points beyond the region of fit, and then only to make a particular vector or array fit a particular size requirement. In reality, you have no idea what your data are doing outside what you’ve measured, so every extrapolation method is — at least in theory — a good as any other.
  2 Commenti
Danielle
Danielle il 7 Nov 2014
I'm sorry, but I don't understand how the answer for the problem looks different from mine if I did extrapolation correctly. I'm confused about the extrapolation process because what I thought was extrapolation doesn't seem to be the answer I've been provided with.
Star Strider
Star Strider il 7 Nov 2014
You’re doing the extrapolations correctly. The reason you’re getting what seem to be strange results is that you’re asking the extrapolation routines to do more than what they were intended to do. The problem with any extrapolation is that regardless of the data you’re extrapolating, in real-world situations, you don’t know what your data are beyond what you have. Therefore any extrapolation, especially far from your known data, could be absolutely spot on or wildly incorrect. You cannot possibly know. Your experiments quite neatly demonstrate that.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Spline Postprocessing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by