Limit Guessing Algorithm

R

ram.rachum

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?
 
R

Roy Smith

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.
 
R

ram.rachum

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.
 
P

Paul Rubin

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.
 
R

ram.rachum

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.
 
P

Paul Rubin

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).
 
R

ram.rachum

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.
 
R

Roberto Bonvallet

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,
 
G

Gordon C

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
 
R

ram.rachum

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, your Zen-Python wisdom is irresistible :)
 
A

Albert Retey

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top