ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 03 May 2016 05:53:07 +0200Limit evaluatation from user input not workinghttps://ask.sagemath.org/question/33297/limit-evaluatation-from-user-input-not-working/ 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.Tue, 03 May 2016 02:31:05 +0200https://ask.sagemath.org/question/33297/limit-evaluatation-from-user-input-not-working/Answer by tmonteil for <p>My code is:</p>
<pre><code>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)
</code></pre>
<p>It gives me this error:</p>
<pre><code>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'
</code></pre>
<p>What am I doing wrong? I want to ask the user the function to be evaluated and the number that x approaches.</p>
https://ask.sagemath.org/question/33297/limit-evaluatation-from-user-input-not-working/?answer=33299#post-id-33299It 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)
Tue, 03 May 2016 05:53:07 +0200https://ask.sagemath.org/question/33297/limit-evaluatation-from-user-input-not-working/?answer=33299#post-id-33299