471,310 Members | 1,468 Online

# Limit Guessing Algorithm

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
10 1323 In article
"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 :-)

Dec 2 '07 #2
On Dec 2, 10:53 pm, Roy Smith <r...@panix.comwrote:
In article

"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 :-)

I'm a third year math undergrad. You probably did not understand my
question.
Dec 2 '07 #3
"ra********@gmail.com" <ra********@gmail.comwrites:

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
On Dec 2, 11:50 pm, Paul Rubin <http://phr...@NOSPAM.invalidwrote:
"ram.rac...@gmail.com" <ram.rac...@gmail.comwrites:
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
"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
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
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
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
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
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.