Ask Your Question
2

limit within a python function

asked 3 years ago

eatdust gravatar image

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?

Thanks in advance.

Preview: (hide)

Comments

Welcome to Ask Sage! Thank you for your question.

slelievre gravatar imageslelievre ( 3 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 3 years ago

slelievre gravatar image

updated 3 years ago

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
Preview: (hide)
link

Comments

Thank you!

eatdust gravatar imageeatdust ( 3 years ago )

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 ( 3 years ago )

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

Stats

Asked: 3 years ago

Seen: 376 times

Last updated: Mar 28 '22