473,549 Members | 3,065 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 1392
In article
<65************ *************** *******@b40g200 0prf.googlegrou ps.com>,
"ra********@gma il.com" <ra********@gma il.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.com wrote:
In article
<6527e349-27ba-4de4-bc29-75ff45117...@b4 0g2000prf.googl egroups.com>,

"ram.rac...@gma il.com" <ram.rac...@gma il.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********@gma il.com" <ra********@gma il.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.i nvalidwrote:
"ram.rac...@gma il.com" <ram.rac...@gma il.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********@gma il.com" <ra********@gma il.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.i nvalidwrote:
"ram.rac...@gma il.com" <ram.rac...@gma il.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...@gma il.com" <ram.rac...@gma il.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(poi nts):
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...@gma il.com" <ram.rac...@gma il.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(poi nts):
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

This thread has been closed and replies have been disabled. Please start a new discussion.