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.Sat, 05 Nov 2016 09:31:50 -0500Errors when plotting zeta function parametricallyhttp://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/ I have the following piece of code:
def f(x):
return(real_part(zeta(1+x*I)).n())
def g(x):
return(imag_part(zeta(1+x*I)).n())
parametric_plot([f(x),g(x)], (x,2,10))
It should be moderately clear what I'm trying to do - I want to produce a plot of Riemann zeta function on the line Re(z)=1 using parametric plotting. However, when I try to plot this, I get an error `TypeError: cannot evaluate symbolic expression numerically`. I also tried the same thing without the `.n()`, but then I get an error `TypeError: unable to coerce to a real number`. I couldn't find any help online.
It's worth noting that trying to plot function f(x) I get the same error with `.n()`, but it works just fine without it (as opposed to parametric plot). Does anyone have an idea how to fix the issue?
Thanks in advance.Wed, 21 Sep 2016 09:46:11 -0500http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/Answer by kcrisman for <p>I have the following piece of code:</p>
<pre><code>def f(x):
return(real_part(zeta(1+x*I)).n())
def g(x):
return(imag_part(zeta(1+x*I)).n())
parametric_plot([f(x),g(x)], (x,2,10))
</code></pre>
<p>It should be moderately clear what I'm trying to do - I want to produce a plot of Riemann zeta function on the line Re(z)=1 using parametric plotting. However, when I try to plot this, I get an error <code>TypeError: cannot evaluate symbolic expression numerically</code>. I also tried the same thing without the <code>.n()</code>, but then I get an error <code>TypeError: unable to coerce to a real number</code>. I couldn't find any help online.</p>
<p>It's worth noting that trying to plot function f(x) I get the same error with <code>.n()</code>, but it works just fine without it (as opposed to parametric plot). Does anyone have an idea how to fix the issue?</p>
<p>Thanks in advance.</p>
http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?answer=34887#post-id-34887You mean something like [this](http://sagecell.sagemath.org/?q=ktndxr)?
![image description](/upfiles/14744766746249283.png)
In doing a lot of things like this [in this project](http://www.math-cs.gordon.edu/~kcrisman/mat338/section-119.html) I had to use things `lambda t: zeta(sig+t*i).real()` because the symbolic version wouldn't handle it, I guess. So lambda functions *and* `.real()`.Wed, 21 Sep 2016 11:50:20 -0500http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?answer=34887#post-id-34887Comment by Wojowu for <p>You mean something like <a href="http://sagecell.sagemath.org/?q=ktndxr">this</a>? </p>
<p><img alt="image description" src="/upfiles/14744766746249283.png"></p>
<p>In doing a lot of things like this <a href="http://www.math-cs.gordon.edu/~kcrisman/mat338/section-119.html">in this project</a> I had to use things <code>lambda t: zeta(sig+t*i).real()</code> because the symbolic version wouldn't handle it, I guess. So lambda functions <em>and</em> <code>.real()</code>.</p>
http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?comment=34890#post-id-34890Thank you very much! I am relatively new to both Python and Sage, so any help is appreciated. By the way (although this isn't strictly relate to my overall question), do you know of a way to make the the plot non-monochromatic? I am thinking of making the hue of the line changing as `x` increases, so that the plot looks rainbow-y.Wed, 21 Sep 2016 16:04:54 -0500http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?comment=34890#post-id-34890Comment by kcrisman for <p>You mean something like <a href="http://sagecell.sagemath.org/?q=ktndxr">this</a>? </p>
<p><img alt="image description" src="/upfiles/14744766746249283.png"></p>
<p>In doing a lot of things like this <a href="http://www.math-cs.gordon.edu/~kcrisman/mat338/section-119.html">in this project</a> I had to use things <code>lambda t: zeta(sig+t*i).real()</code> because the symbolic version wouldn't handle it, I guess. So lambda functions <em>and</em> <code>.real()</code>.</p>
http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?comment=34897#post-id-34897Hmm, it's certainly possible [(see here)](http://matplotlib.org/examples/pylab_examples/multicolored_line.html) but I don't think we've "wrapped" that matplotlib functionality. See https://trac.sagemath.org/ticket/21564Thu, 22 Sep 2016 12:21:58 -0500http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?comment=34897#post-id-34897Answer by FrédéricC for <p>I have the following piece of code:</p>
<pre><code>def f(x):
return(real_part(zeta(1+x*I)).n())
def g(x):
return(imag_part(zeta(1+x*I)).n())
parametric_plot([f(x),g(x)], (x,2,10))
</code></pre>
<p>It should be moderately clear what I'm trying to do - I want to produce a plot of Riemann zeta function on the line Re(z)=1 using parametric plotting. However, when I try to plot this, I get an error <code>TypeError: cannot evaluate symbolic expression numerically</code>. I also tried the same thing without the <code>.n()</code>, but then I get an error <code>TypeError: unable to coerce to a real number</code>. I couldn't find any help online.</p>
<p>It's worth noting that trying to plot function f(x) I get the same error with <code>.n()</code>, but it works just fine without it (as opposed to parametric plot). Does anyone have an idea how to fix the issue?</p>
<p>Thanks in advance.</p>
http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?answer=34886#post-id-34886try like this:
f=lambda x: zeta(1+x*I).real_part()
g=lambda x: zeta(1+x*I).imag_part()
parametric_plot([f,g], (x,2,10))
Wed, 21 Sep 2016 11:48:02 -0500http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?answer=34886#post-id-34886Comment by slelievre for <p>try like this:</p>
<pre><code>f=lambda x: zeta(1+x*I).real_part()
g=lambda x: zeta(1+x*I).imag_part()
parametric_plot([f,g], (x,2,10))
</code></pre>
http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?comment=35455#post-id-35455@Wojowu - you can upvote the answer if you find it useful!Sat, 05 Nov 2016 09:31:50 -0500http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?comment=35455#post-id-35455Comment by Wojowu for <p>try like this:</p>
<pre><code>f=lambda x: zeta(1+x*I).real_part()
g=lambda x: zeta(1+x*I).imag_part()
parametric_plot([f,g], (x,2,10))
</code></pre>
http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?comment=34891#post-id-34891Thank you very much! I am relatively new to both Python and Sage, so any help is appreciated.Wed, 21 Sep 2016 16:05:06 -0500http://ask.sagemath.org/question/34882/errors-when-plotting-zeta-function-parametrically/?comment=34891#post-id-34891