Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

Limit evaluatation from user input not working

asked 8 years ago

user6502 gravatar image

My code is:

t = raw_input()
#n = var('x')
u2 = raw_input()
(t).limit(x=u2)
(t).limit(x=u2+0.001)
(t).limit(x=u2+0.0001)

It gives me this error:

Error in lines 4-4
Traceback (most recent call last):
  File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
    exec compile(block+'\n', '', 'single') in namespace, locals
  File "", line 1, in <module>
AttributeError: 'unicode' object has no attribute 'limit'

What am I doing wrong? I want to ask the user the function to be evaluated and the number that x approaches.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 8 years ago

tmonteil gravatar image

It is not clear what should the user enter, but if it is something like sin(x) for t and pi for u2, you have to understand that when you write sin(x) in the command line, you create a symbolic object, corresponding to the mathematical function sin(x). When you type "sin(x)" as an input of raw_input(), the function returns the string "sin(x)", not the symbolic mathematical function. So you have to transform this string as a symbolic expression, that is an element of the symbolic ring, for this you should replace the string t by SR(t) (idem for u2):

sage: SR(t).limit(x=SR(u2)+0.001)
Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 8 years ago

Seen: 286 times

Last updated: May 03 '16