By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

Limit Guessing Algorithm

P: n/a
Hello hello,

I'm looking for a piece of code, preferably in Python, that will do
the following. It will accept a few data points (x,f(x)) of a function
that converges to some finite value when x converges to infinity. I
need the algorithm to guess what that limit is, to whatever precision
it can.

For example, if the input is:

[
[1,8],
[2,7.5],
[3,7.25],
[4,7.125]
]

Then the output will be 7. Or at least something close.

Does anyone know anything like that?
Dec 2 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
In article
<65**********************************@b40g2000prf. googlegroups.com>,
"ra********@gmail.com" <ra********@gmail.comwrote:
Hello hello,

I'm looking for a piece of code, preferably in Python, that will do
the following. It will accept a few data points (x,f(x)) of a function
that converges to some finite value when x converges to infinity. I
need the algorithm to guess what that limit is, to whatever precision
it can.

For example, if the input is:

[
[1,8],
[2,7.5],
[3,7.25],
[4,7.125]
]

Then the output will be 7. Or at least something close.

Does anyone know anything like that?
I suggest any introductory calculus or math analysis text. Perhaps even
the one your professor assigned you for the course :-)

Look under "limits" in the table of contents.
Dec 2 '07 #2

P: n/a
On Dec 2, 10:53 pm, Roy Smith <r...@panix.comwrote:
In article
<6527e349-27ba-4de4-bc29-75ff45117...@b40g2000prf.googlegroups.com>,

"ram.rac...@gmail.com" <ram.rac...@gmail.comwrote:
Hello hello,
I'm looking for a piece of code, preferably in Python, that will do
the following. It will accept a few data points (x,f(x)) of a function
that converges to some finite value when x converges to infinity. I
need the algorithm to guess what that limit is, to whatever precision
it can.
For example, if the input is:
[
[1,8],
[2,7.5],
[3,7.25],
[4,7.125]
]
Then the output will be 7. Or at least something close.
Does anyone know anything like that?

I suggest any introductory calculus or math analysis text. Perhaps even
the one your professor assigned you for the course :-)

Look under "limits" in the table of contents.
I'm a third year math undergrad. You probably did not understand my
question.
Dec 2 '07 #3

P: n/a
"ra********@gmail.com" <ra********@gmail.comwrites:
Look under "limits" in the table of contents.

I'm a third year math undergrad. You probably did not understand my
question.
I think I understood the question. It sounds like a numerical methods
homework problem. Basically you have f(x0), f(x1), etc. and you want
to extrapolate to x=infinity. Hint: think of a0=1/x0, a1=1/x1, etc.
so your initial data is f(1/a0), f(1/a1), etc. and it should be pretty
obvious what to do next.
Dec 2 '07 #4

P: n/a
On Dec 2, 11:50 pm, Paul Rubin <http://phr...@NOSPAM.invalidwrote:
"ram.rac...@gmail.com" <ram.rac...@gmail.comwrites:
Look under "limits" in the table of contents.
I'm a third year math undergrad. You probably did not understand my
question.

I think I understood the question. It sounds like a numerical methods
homework problem. Basically you have f(x0), f(x1), etc. and you want
to extrapolate to x=infinity. Hint: think of a0=1/x0, a1=1/x1, etc.
so your initial data is f(1/a0), f(1/a1), etc. and it should be pretty
obvious what to do next.
Well Paul, it's not obvious to me, so if you could explain it I'll be
grateful.

Also, this is not a homework assignment. This is something I need for
some physical simulations I'm writing.

Thank you,
Ram.
Dec 2 '07 #5

P: n/a
"ra********@gmail.com" <ra********@gmail.comwrites:
I think I understood the question. It sounds like a numerical methods
homework problem. Basically you have f(x0), f(x1), etc. and you want
to extrapolate to x=infinity. Hint: think of a0=1/x0, a1=1/x1, etc.
so your initial data is f(1/a0), f(1/a1), etc. and it should be pretty
obvious what to do next.

Well Paul, it's not obvious to me, so if you could explain it I'll be
grateful.
Basically define g(x) = f(1/x). So you have this g(a0), g(a1), g(a2), ...
and you can fit a curve through them with your favorite extrapolation
formula (see a numerics book for lots of choices). Then compute g(0).
Dec 2 '07 #6

P: n/a
On Dec 3, 12:02 am, Paul Rubin <http://phr...@NOSPAM.invalidwrote:
"ram.rac...@gmail.com" <ram.rac...@gmail.comwrites:
I think I understood the question. It sounds like a numerical methods
homework problem. Basically you have f(x0), f(x1), etc. and you want
to extrapolate to x=infinity. Hint: think of a0=1/x0, a1=1/x1, etc.
so your initial data is f(1/a0), f(1/a1), etc. and it should be pretty
obvious what to do next.
Well Paul, it's not obvious to me, so if you could explain it I'll be
grateful.

Basically define g(x) = f(1/x). So you have this g(a0), g(a1), g(a2), ...
and you can fit a curve through them with your favorite extrapolation
formula (see a numerics book for lots of choices). Then compute g(0).
Thank you Paul. This seems to make sense :)
I'll try to implement it.

Best Wishes,
Ram.
Dec 2 '07 #7

P: n/a
On Dec 2, 5:27 pm, "ram.rac...@gmail.com" <ram.rac...@gmail.com>
wrote:
It will accept a few data points (x,f(x)) of a function
that converges to some finite value when x converges to infinity. I
need the algorithm to guess what that limit is.
Since there are an infinity of ways to estimate the limit, I suggest
sticking to the simplest one:

def guess_limit(points):
x, y = max(points)
return y
[
[1,8],
[2,7.5],
[3,7.25],
[4,7.125]
]
Then the output will be 7. Or at least something close.
For this data set, my function will return 7.125. Is it close enough?
Finding a better estimation is more a math problem than a Python one.

Best regards,
--
Roberto Bonvallet
Dec 2 '07 #8

P: n/a
On Dec 3, 1:33 am, Roberto Bonvallet <rbonv...@gmail.comwrote:
On Dec 2, 5:27 pm, "ram.rac...@gmail.com" <ram.rac...@gmail.com>
wrote:
It will accept a few data points (x,f(x)) of a function
that converges to some finite value when x converges to infinity. I
need the algorithm to guess what that limit is.

Since there are an infinity of ways to estimate the limit, I suggest
sticking to the simplest one:

def guess_limit(points):
x, y = max(points)
return y
[
[1,8],
[2,7.5],
[3,7.25],
[4,7.125]
]
Then the output will be 7. Or at least something close.

For this data set, my function will return 7.125. Is it close enough?
Finding a better estimation is more a math problem than a Python one.

Best regards,
--
Roberto Bonvallet
Roberto, your Zen-Python wisdom is irresistible :)
Dec 3 '07 #9

P: n/a
Hi,
>
I'm looking for a piece of code, preferably in Python, that will do
the following. It will accept a few data points (x,f(x)) of a function
that converges to some finite value when x converges to infinity. I
need the algorithm to guess what that limit is, to whatever precision
it can.

For example, if the input is:

[
[1,8],
[2,7.5],
[3,7.25],
[4,7.125]
]

Then the output will be 7. Or at least something close.

Does anyone know anything like that?
It is obvious that in general this is an unsolvable problem. But if you
know for some reason that your series/functions are "well behaved" in
some sense it still might be possible to do something reasonable and
there has some work been done on these things. You might e.g. google for
Wynns epsilon method which gives some examples and references for
related stuff.

hth,

albert
Dec 3 '07 #10

P: n/a
One of the difficulties of this kind of a problem is that one is looking for
a solution to a limited number of data points for which it may be possible
to define a function. There can never be a guarantee that the chosen "fit"
can be reliably extrapolated. You need to tie a possible solution to the
realworld characteristics of that data. Just taking a bunch of data by
itself cannot be sufficient.
Gord
Dec 3 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.