plotting prime_pi

i like this post (click again to cancel)
1
i dont like this post (click again to cancel)

Maybe I am missing something really simple, but shouldn't one be able to plot prime_pi?


----------------------------------------------------------------------
| Sage Version 4.5.1, Release Date: 2010-07-19                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
sage: plot(prime_pi(x),3,10)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/home/dept/finotti/<ipython console=""> in <module>()

/scratch/local/sage-4.5.1/local/lib/python2.6/site-packages/sage/functions/prime_pi.so in sage.functions.prime_pi.PrimePi.__call__ (sage/functions/prime_pi.c:1064)()

/scratch/local/sage-4.5.1/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.__int__ (sage/symbolic/expression.cpp:4171)()

/scratch/local/sage-4.5.1/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.n (sage/symbolic/expression.cpp:17042)()

TypeError: cannot evaluate symbolic expression numerically

It seems wot work fine with real input


sage: prime_pi(pi)
_3 = 2
sage: prime_pi(1020.312788)
_4 = 171

Thanks,

Luis

asked Sep 07 '10

finotti gravatar image finotti
51 3 6

3 Answers:

i like this answer (click again to cancel)
4
i dont like this answer (click again to cancel)

Essentially, prime_pi has its own plotting method, so you need to do

sage: plot(prime_pi, 50,100)

You can see this at

sage: prime_pi?

However, you are right that it should play nicely with other plotting syntax, which is why we have the ticket here tracking this issue.

link

posted Sep 07 '10

kcrisman gravatar image kcrisman
6784 14 67 152
i like this answer (click again to cancel)
0
i dont like this answer (click again to cancel)

Yes, you should be able to plot prime_pi, using just the code you tried! Unfortunately it seems that plot can not always figure out what to evaluate, so you have to help it a little, using a lambda function:

sage: plot(lambda x: prime_pi(x),3,10)

or, equivalently,

sage: f = lambda x: prime_pi(x)
sage: plot(f,3,10)

There have been a number of similar problems with similar solutions mentioned on this site . . . maybe eventually someone will extend plot so that the code you tried first will work. At least in the meantime someone could change the error message to suggest trying lambda functions . . .

Also, could you tell us where you read about the plot function? It could be very useful to include an example like this somewhere that people will find it :)

link

posted Sep 07 '10

niles gravatar image niles
3429 5 41 94
http://nilesjohnson.net/

updated Sep 07 '10

In this case, no lambda needed - see below. Niles, maybe you want to fix this ticket? :) kcrisman (Sep 07 '10)
ha! I certainly *want* to . . . niles (Sep 07 '10)
i like this answer (click again to cancel)
0
i dont like this answer (click again to cancel)

list_plot([(x,prime_pi(x)) for x in xrange(3,10+1)])

link

posted Sep 07 '10

ccanonc gravatar image ccanonc
477 3 15 32

updated Sep 07 '10

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

1 follower

Tags:

Stats:

Asked: Sep 07 '10

Seen: 274 times

Last updated: Sep 07 '10

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.