Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
linear extrapolation

Subject: linear extrapolation

From: Asghar

Date: 16 Apr, 2010 18:06:22

Message: 1 of 13

Hi guys,

I've plotted a graph from some values ending at x =10 000.. Now i need to extrapolate this to x=1000 000 to obtain the corresponding value of y. I can't find out how to do it. I tried the interp function but it does not work. Help please?

Subject: linear extrapolation

From: Roger Stafford

Date: 16 Apr, 2010 20:44:20

Message: 2 of 13

"Asghar " <asgharally@hotmail.com> wrote in message <hqa8uu$g95$1@fred.mathworks.com>...
> Hi guys,
>
> I've plotted a graph from some values ending at x =10 000.. Now i need to extrapolate this to x=1000 000 to obtain the corresponding value of y. I can't find out how to do it. I tried the interp function but it does not work. Help please?

  There's a reason why 'interp1' won't allow you to do extrapolation as extended as you propose. The very purpose of interpolation and extrapolation is to make educated guesses as to the values of functions that you haven't directly computed or measured, but rather based on their nearby values and a tacit assumption of some kind of continuity in the functions and their derivatives. When you propose to go outside the known range of values by a factor of a hundred to one, one would usually conclude that the result would be essentially meaningless. Is there something special about your data that makes it otherwise?

Roger Stafford

Subject: linear extrapolation

From: Asghar

Date: 16 Apr, 2010 20:54:04

Message: 3 of 13

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hqai74$qb$1@fred.mathworks.com>...
> "Asghar " <asgharally@hotmail.com> wrote in message <hqa8uu$g95$1@fred.mathworks.com>...
> > Hi guys,
> >
> > I've plotted a graph from some values ending at x =10 000.. Now i need to extrapolate this to x=1000 000 to obtain the corresponding value of y. I can't find out how to do it. I tried the interp function but it does not work. Help please?
>
> There's a reason why 'interp1' won't allow you to do extrapolation as extended as you propose. The very purpose of interpolation and extrapolation is to make educated guesses as to the values of functions that you haven't directly computed or measured, but rather based on their nearby values and a tacit assumption of some kind of continuity in the functions and their derivatives. When you propose to go outside the known range of values by a factor of a hundred to one, one would usually conclude that the result would be essentially meaningless. Is there something special about your data that makes it otherwise?
>
> Roger Stafford

Well i had to time the elapsed time to sort out some randum numbers using bubblesort. I had to stop the random numbers to 10000 and plot time against numbers. And then i'm asked to find the time required to sort out by 1000000 and it says to find out by extrapolation. Is there any function for this? Would i get any meaningful answer?

Subject: linear extrapolation

From: Steven Lord

Date: 16 Apr, 2010 21:12:51

Message: 4 of 13


"Asghar " <asgharally@hotmail.com> wrote in message
news:hqaipc$alq$1@fred.mathworks.com...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
> message <hqai74$qb$1@fred.mathworks.com>...
>> "Asghar " <asgharally@hotmail.com> wrote in message
>> <hqa8uu$g95$1@fred.mathworks.com>...
>> > Hi guys,
>> >
>> > I've plotted a graph from some values ending at x =10 000.. Now i need
>> > to extrapolate this to x=1000 000 to obtain the corresponding value of
>> > y. I can't find out how to do it. I tried the interp function but it
>> > does not work. Help please?
>>
>> There's a reason why 'interp1' won't allow you to do extrapolation as
>> extended as you propose. The very purpose of interpolation and
>> extrapolation is to make educated guesses as to the values of functions
>> that you haven't directly computed or measured, but rather based on their
>> nearby values and a tacit assumption of some kind of continuity in the
>> functions and their derivatives. When you propose to go outside the
>> known range of values by a factor of a hundred to one, one would usually
>> conclude that the result would be essentially meaningless. Is there
>> something special about your data that makes it otherwise?
>>
>> Roger Stafford
>
> Well i had to time the elapsed time to sort out some randum numbers using
> bubblesort. I had to stop the random numbers to 10000 and plot time
> against numbers. And then i'm asked to find the time required to sort out
> by 1000000 and it says to find out by extrapolation. Is there any function
> for this? Would i get any meaningful answer?

Well, you could simply fit a straight line to the data you have and evaluate
that fitted line ... but that won't help if the underlying relationship
between x and your time data is quadratic.

Okay, so you can fit a quadratic curve to the data you have and evaluate
that ... but again, that won't help if the underlying relationship is
sinusoidal.

So let's fit a sinusoidal curve to the data you have ...

Hopefully this shows why extrapolating so far from the data you have can be
dangerous at worst.

Now that being said, the shorter the distance you have to extrapolate, or
the better you know the relationship between your two variables, the better.
Using the timing data for generating between 1 and 10000 random numbers
should give you a fairly good estimate for how long it'll take to generate
10100 random numbers. But a million? Probably not quite as good.

If you really do need to perform this extrapolation, look at the
documentation for INTERP1 and notice the parameter after the "method" input.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/interp1.html

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: linear extrapolation

From: Asghar

Date: 16 Apr, 2010 21:25:05

Message: 5 of 13

the curve isn't actually a proper one.. then i've used the polyval function and then did a line of best fit. i thought i could extrapolate that line using matlab. is there a way of obtaining the function of that line? and then i could just work it out without matlab by doing calculations for linear extrapolation.

"Steven Lord" <slord@mathworks.com> wrote in message <hqajsh$st3$1@fred.mathworks.com>...
>
> "Asghar " <asgharally@hotmail.com> wrote in message
> news:hqaipc$alq$1@fred.mathworks.com...
> > "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in
> > message <hqai74$qb$1@fred.mathworks.com>...
> >> "Asghar " <asgharally@hotmail.com> wrote in message
> >> <hqa8uu$g95$1@fred.mathworks.com>...
> >> > Hi guys,
> >> >
> >> > I've plotted a graph from some values ending at x =10 000.. Now i need
> >> > to extrapolate this to x=1000 000 to obtain the corresponding value of
> >> > y. I can't find out how to do it. I tried the interp function but it
> >> > does not work. Help please?
> >>
> >> There's a reason why 'interp1' won't allow you to do extrapolation as
> >> extended as you propose. The very purpose of interpolation and
> >> extrapolation is to make educated guesses as to the values of functions
> >> that you haven't directly computed or measured, but rather based on their
> >> nearby values and a tacit assumption of some kind of continuity in the
> >> functions and their derivatives. When you propose to go outside the
> >> known range of values by a factor of a hundred to one, one would usually
> >> conclude that the result would be essentially meaningless. Is there
> >> something special about your data that makes it otherwise?
> >>
> >> Roger Stafford
> >
> > Well i had to time the elapsed time to sort out some randum numbers using
> > bubblesort. I had to stop the random numbers to 10000 and plot time
> > against numbers. And then i'm asked to find the time required to sort out
> > by 1000000 and it says to find out by extrapolation. Is there any function
> > for this? Would i get any meaningful answer?
>
> Well, you could simply fit a straight line to the data you have and evaluate
> that fitted line ... but that won't help if the underlying relationship
> between x and your time data is quadratic.
>
> Okay, so you can fit a quadratic curve to the data you have and evaluate
> that ... but again, that won't help if the underlying relationship is
> sinusoidal.
>
> So let's fit a sinusoidal curve to the data you have ...
>
> Hopefully this shows why extrapolating so far from the data you have can be
> dangerous at worst.
>
> Now that being said, the shorter the distance you have to extrapolate, or
> the better you know the relationship between your two variables, the better.
> Using the timing data for generating between 1 and 10000 random numbers
> should give you a fairly good estimate for how long it'll take to generate
> 10100 random numbers. But a million? Probably not quite as good.
>
> If you really do need to perform this extrapolation, look at the
> documentation for INTERP1 and notice the parameter after the "method" input.
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/interp1.html
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Subject: linear extrapolation

From: Roger Stafford

Date: 16 Apr, 2010 22:02:22

Message: 6 of 13

"Asghar " <asgharally@hotmail.com> wrote in message <hqaipc$alq$1@fred.mathworks.com>...
> Well i had to time the elapsed time to sort out some randum numbers using bubblesort. I had to stop the random numbers to 10000 and plot time against numbers. And then i'm asked to find the time required to sort out by 1000000 and it says to find out by extrapolation. Is there any function for this? Would i get any meaningful answer?

  Now that you've told us this value is the time required in a bubblesort operation, that changes the whole picture. It is known that optimum sorting requires a number of steps of the order of n*log(n) for sorting n numbers. If we assume your bubblesort operation is anywhere near optimum, then the best assumption you could probably make would be to find a best fit - that is, pick the best value for a - for

 t = a*n*log(n)

over the range from n = 1 to 10000, and use that for n = 1000000. It still wouldn't be reliable but that's about the best you can do under the circumstances.

Roger Stafford

Subject: linear extrapolation

From: John D'Errico

Date: 16 Apr, 2010 22:09:05

Message: 7 of 13

"Asghar " <asgharally@hotmail.com> wrote in message <hqakjh$d2i$1@fred.mathworks.com>...
> the curve isn't actually a proper one.. then i've used the polyval function and then did a line of best fit. i thought i could extrapolate that line using matlab. is there a way of obtaining the function of that line? and then i could just work it out without matlab by doing calculations for linear extrapolation.
>

If you have used polyfit, then polyval can evaluate the
function at ANY point. If that point is outside the
support of the data, then you are extrapolating.
Admittedly, extrapolation that far outside is generally
a meaningless operation.

So there should be no problem. Just use polyval, and
do the extrapolation as requested.

John

Subject: linear extrapolation

From: James Tursa

Date: 16 Apr, 2010 22:13:05

Message: 8 of 13

"Asghar " <asgharally@hotmail.com> wrote in message <hqaipc$alq$1@fred.mathworks.com>...
>
> Well i had to time the elapsed time to sort out some randum numbers using bubblesort.

Of course, bubble sort is pretty much the absolute worst possible sorting method ... I am going to assume that this is part of an exercise in demonstrating that.

James Tursa

Subject: linear extrapolation

From: Roger Stafford

Date: 16 Apr, 2010 22:17:20

Message: 9 of 13

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hqampe$hme$1@fred.mathworks.com>...
> Now that you've told us this value is the time required in a bubblesort operation, that changes the whole picture. It is known that optimum sorting requires a number of steps of the order of n*log(n) for sorting n numbers. If we assume your bubblesort operation is anywhere near optimum, then the best assumption you could probably make would be to find a best fit - that is, pick the best value for a - for
>
> t = a*n*log(n)
>
> over the range from n = 1 to 10000, and use that for n = 1000000. It still wouldn't be reliable but that's about the best you can do under the circumstances.
>
> Roger Stafford

  Let me amend that last bit of advice a bit. You should allow for some kind of fixed overhead on your calls to a bubblesort routine by getting the best a and b for t = a*n*log(n) + b, or else take only values of n from, say, n = 1000 to n = 10000, something like that. The low values of n will probably be somewhat misleading for predicting extrapolated values.

Roger Stafford

Subject: linear extrapolation

From: Roger Stafford

Date: 16 Apr, 2010 22:29:05

Message: 10 of 13

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hqanlg$1un$1@fred.mathworks.com>...
> Let me amend that last bit of advice a bit. You should allow for some kind of fixed overhead on your calls to a bubblesort routine by getting the best a and b for t = a*n*log(n) + b, or else take only values of n from, say, n = 1000 to n = 10000, something like that. The low values of n will probably be somewhat misleading for predicting extrapolated values.
>
> Roger Stafford

  Come to think of it, as James has said, bubblesort is not very efficient and, in at least the worst case, tends to be order n-squared, so maybe you had better find the best fitting quadratic function in n instead of n*log(n).

  It's hard to be sure, and that in turn should show you how unreliable this general kind of far-reaching extrapolation is likely to be.

Roger Stafford

Subject: linear extrapolation

From: Asghar

Date: 16 Apr, 2010 22:50:20

Message: 11 of 13

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hqaobh$c6m$1@fred.mathworks.com>...
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hqanlg$1un$1@fred.mathworks.com>...
> > Let me amend that last bit of advice a bit. You should allow for some kind of fixed overhead on your calls to a bubblesort routine by getting the best a and b for t = a*n*log(n) + b, or else take only values of n from, say, n = 1000 to n = 10000, something like that. The low values of n will probably be somewhat misleading for predicting extrapolated values.
> >
> > Roger Stafford
>
> Come to think of it, as James has said, bubblesort is not very efficient and, in at least the worst case, tends to be order n-squared, so maybe you had better find the best fitting quadratic function in n instead of n*log(n).
>
> It's hard to be sure, and that in turn should show you how unreliable this general kind of far-reaching extrapolation is likely to be.
>
> Roger Stafford

ok thank but how do i get the best values of a and b? :s i'm not very good at this and it is getting quite confusing :S sorry about that guys

Subject: linear extrapolation

From: John D'Errico

Date: 16 Apr, 2010 22:58:05

Message: 12 of 13

"Asghar " <asgharally@hotmail.com> wrote in message <hqapjc$2ec$1@fred.mathworks.com>...

> ok thank but how do i get the best values of a and b? :s i'm not very good at this and it is getting quite confusing :S sorry about that guys

You will never get to be good unless you make some
effort of your own. Simply giving up and saying that
you are not good at it is a way to ensure that you
will never learn. And we don't terribly want to just
enable you to not learn.

help polyfit

Read the help. Make an effort.

John

Subject: linear extrapolation

From: Asghar

Date: 16 Apr, 2010 23:21:05

Message: 13 of 13

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <hqaq1t$99q$1@fred.mathworks.com>...
> "Asghar " <asgharally@hotmail.com> wrote in message <hqapjc$2ec$1@fred.mathworks.com>...
>
> > ok thank but how do i get the best values of a and b? :s i'm not very good at this and it is getting quite confusing :S sorry about that guys
>
> You will never get to be good unless you make some
> effort of your own. Simply giving up and saying that
> you are not good at it is a way to ensure that you
> will never learn. And we don't terribly want to just
> enable you to not learn.
>
> help polyfit
>
> Read the help. Make an effort.
>
> John

yes i have been reading :) trying my best to understand all this but right now it's too much..
i've read about the polyval and polyfit but i can't really understand what is the difference and what is the output i get?

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us