Ask Your Question

limit within a python function

asked 2022-03-25 14:17:15 +0200

eatdust gravatar image

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

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


which always returns: 1/y...

How shall I specify that x should be a var?

Thanks in advance.

edit retag flag offensive close merge delete


Welcome to Ask Sage! Thank you for your question.

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

1 Answer

Sort by ยป oldest newest most voted

answered 2022-03-26 08:19:33 +0200

slelievre gravatar image

updated 2022-03-28 09:46:08 +0200

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):
    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)
edit flag offensive delete link more


Thank you!

eatdust gravatar imageeatdust ( 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.

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2022-03-25 14:17:15 +0200

Seen: 44 times

Last updated: Mar 28