ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 02 Oct 2016 03:34:09 -0500Plotting point when coordinate involves symbolic and numerical valueshttp://ask.sagemath.org/question/34937/plotting-point-when-coordinate-involves-symbolic-and-numerical-values/Consider the following single piece of code:
point([real_part(zeta(I))+1,0])
When trying to compile it, I get the following error message:
Error in lines 1-1
Traceback (most recent call last):
File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 957, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/sage/plot/point.py", line 353, in point
return point3d(points, **kwds)
File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/sage/plot/plot3d/shapes2.py", line 1143, in point3d
A = sum([Point(z, size, **kwds) for z in v])
File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/sage/plot/plot3d/shapes2.py", line 720, in __init__
self.loc = (float(center[0]), float(center[1]), float(center[2]))
TypeError: 'sage.symbolic.expression.Expression' object does not support indexing
Is there some simple way to fix this?
Interesting note: I have played around with this error, and it is very unclear to me when it does or doesn't appear. Here are some examples of when the error *does* appear (as far as I've checked, the traceback is always the same):
point([real_part(zeta(I))+1,0])
point([real_part(zeta(I))*2,0])
point([real_part(zeta(I))+real_part(zeta(I)),0])
point([real_part(zeta(I))/2,0])
point([real_part(zeta(I))-real_part(zeta(2*I)),0])
Here are some examples where it *doesn't* appear:
point([real_part(zeta(I))+0,0])
point([real_part(zeta(I))*1,0])
point([real_part(zeta(I))*real_part(zeta(I)),0])
point([real_part(zeta(I))+real_part(zeta(2*I)),0])
point([real_part(zeta(I))+imag_part(zeta(I)),0])
(edit: the error doesn't seem to ever occur if we give the zeta function a real argument)
I'd be interested if someone figured out under what conditions the error appears or not, because I fail to see any pattern. Thank you in advance.Sun, 25 Sep 2016 13:21:03 -0500http://ask.sagemath.org/question/34937/plotting-point-when-coordinate-involves-symbolic-and-numerical-values/Answer by tmonteil for <p>Consider the following single piece of code:</p>
<pre><code>point([real_part(zeta(I))+1,0])
</code></pre>
<p>When trying to compile it, I get the following error message:</p>
<pre><code>Error in lines 1-1
Traceback (most recent call last):
File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 957, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/sage/plot/point.py", line 353, in point
return point3d(points, **kwds)
File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/sage/plot/plot3d/shapes2.py", line 1143, in point3d
A = sum([Point(z, size, **kwds) for z in v])
File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/sage/plot/plot3d/shapes2.py", line 720, in __init__
self.loc = (float(center[0]), float(center[1]), float(center[2]))
TypeError: 'sage.symbolic.expression.Expression' object does not support indexing
</code></pre>
<p>Is there some simple way to fix this?</p>
<p>Interesting note: I have played around with this error, and it is very unclear to me when it does or doesn't appear. Here are some examples of when the error <em>does</em> appear (as far as I've checked, the traceback is always the same):</p>
<pre><code>point([real_part(zeta(I))+1,0])
point([real_part(zeta(I))*2,0])
point([real_part(zeta(I))+real_part(zeta(I)),0])
point([real_part(zeta(I))/2,0])
point([real_part(zeta(I))-real_part(zeta(2*I)),0])
</code></pre>
<p>Here are some examples where it <em>doesn't</em> appear:</p>
<pre><code>point([real_part(zeta(I))+0,0])
point([real_part(zeta(I))*1,0])
point([real_part(zeta(I))*real_part(zeta(I)),0])
point([real_part(zeta(I))+real_part(zeta(2*I)),0])
point([real_part(zeta(I))+imag_part(zeta(I)),0])
</code></pre>
<p>(edit: the error doesn't seem to ever occur if we give the zeta function a real argument)</p>
<p>I'd be interested if someone figured out under what conditions the error appears or not, because I fail to see any pattern. Thank you in advance.</p>
http://ask.sagemath.org/question/34937/plotting-point-when-coordinate-involves-symbolic-and-numerical-values/?answer=34939#post-id-34939First, i can not reproduce your problem on Sage `7.4.beta6`. Which version are you using ? Perhaps upgrading will solve your issue.
Meanwhile, you should fix your problem by explicitely transforming your symbolic expression into a floating-point number:
sage: point([RDF(real_part(zeta(I))+1),0])
Launched png viewer for Graphics object consisting of 1 graphSun, 25 Sep 2016 15:13:28 -0500http://ask.sagemath.org/question/34937/plotting-point-when-coordinate-involves-symbolic-and-numerical-values/?answer=34939#post-id-34939Comment by Wojowu for <p>First, i can not reproduce your problem on Sage <code>7.4.beta6</code>. Which version are you using ? Perhaps upgrading will solve your issue.</p>
<p>Meanwhile, you should fix your problem by explicitely transforming your symbolic expression into a floating-point number:</p>
<pre><code>sage: point([RDF(real_part(zeta(I))+1),0])
Launched png viewer for Graphics object consisting of 1 graph
</code></pre>
http://ask.sagemath.org/question/34937/plotting-point-when-coordinate-involves-symbolic-and-numerical-values/?comment=35029#post-id-35029Hello, sorry for a late reply, I was away from home. I am using SageMathCloud, and I'm not sure what version it's running (my guess is 7.3, latest stable). I also have version 7.2 downloaded on a Windows machine, but I didn't try running the code there, and I don't know where I could download beta versions. Anyways, using RDF fixed the problem, so I am willing to accept this answer.Sun, 02 Oct 2016 03:34:09 -0500http://ask.sagemath.org/question/34937/plotting-point-when-coordinate-involves-symbolic-and-numerical-values/?comment=35029#post-id-35029Comment by eric_g for <p>First, i can not reproduce your problem on Sage <code>7.4.beta6</code>. Which version are you using ? Perhaps upgrading will solve your issue.</p>
<p>Meanwhile, you should fix your problem by explicitely transforming your symbolic expression into a floating-point number:</p>
<pre><code>sage: point([RDF(real_part(zeta(I))+1),0])
Launched png viewer for Graphics object consisting of 1 graph
</code></pre>
http://ask.sagemath.org/question/34937/plotting-point-when-coordinate-involves-symbolic-and-numerical-values/?comment=34943#post-id-34943I can reproduce the problem with Sage 7.3 and Sage 7.4.beta1, so probably it has been fixed somewhere between 7.4.beta1 and 7.4.beta6.Mon, 26 Sep 2016 02:39:10 -0500http://ask.sagemath.org/question/34937/plotting-point-when-coordinate-involves-symbolic-and-numerical-values/?comment=34943#post-id-34943