# limit within a python function

Hi there, total beginner in Sage, and this drives me mad:

def mylimit(f,x,a):
return f.limit(x=a)

var('y')
mylimit(1/y,y,2).show()


which always returns: 1/y...

How shall I specify that x should be a var?

edit retag close merge delete

( 2022-03-26 08:14:35 +0200 )edit

Sort by ยป oldest newest most voted

Defining a variable inside the function, we can use it for the limit.

For example, define t and substitute it for the variable provided by the user.

Applying this idea, we can define myfunction as follows:

def mylimit(f, x, a):
r"""
Return the limit of the expression f when x tends to a.
"""
t = SR.var('t')
return f.subs({x: t}).limit(t=a)


With that definition:

sage: mylimit(1/y, y, 2)
1/2

more

Thank you!

( 2022-03-28 09:27:57 +0200 )edit

You are welcome. If it solves the question, you can mark the answer as accepted by clicking the "accept" button next to it (the button with a check mark). This also marks the question as solved in the list of questions.

( 2022-03-28 09:47:19 +0200 )edit