Ask Your Question
1

Using Sage plotting capability on data from PARI/GP (1)

asked 2018-02-09 09:20:43 -0500

RuudH gravatar image

This is a short follow-up question from this one.

I would like to produce an implicit plot (a contour plot where the real or imaginary values of a function are zero):

var('x,y,s')
g=real(zeta(s))
implicit_plot(lambda x,y:g(x+y*I),(x,-3,3),(y,-3,3))

This works fine, however I want to use GP/Pari to evaluate the zeta function and therefore wrote:

var('x,y')
g=gp("H(s)=zeta(s)")
implicit_plot(lambda x,y:real_part(g(x+y*I)),(x,-3,3),(y,-3,3))

but then keep getting an error message:

PARI/GP ERROR: at top-level: sage[45020]=sage[16][1] ^--- incorrect type in _[_] OCcompo1 [not a vector] (t_REAL).*

For 'normal' plots like this one:

var('x')
g=gp("H(s)=real(zeta(s))")
plot(lambda x:(g(x)),(x,3,6))

the interface with GP works fine, so I probably do something wrong using multiple variables or complex numbers? It doesn't seem to be zeta-function specific (like the pole at s=1), since it also fails for e.g. the cos-function.

Grateful for any advice on how to make this work.

Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-02-09 10:31:32 -0500

tmonteil gravatar image

The issue is the following:

sage: a = g(2+I) ; a
1.1503557032549026717428499347448667156 - 0.43753086591960788111752789859284305987*I
sage: type(a)
<class 'sage.interfaces.gp.GpElement'>
sage: real(a)
TypeError: Error executing code in GP

So, Sage is not able to take the real part of a GP complex number. Let me suggest to first transform the GP number into a Sage Complex Double Element, and then work with that:

sage: CDF(a)
1.1503557032549028 - 0.4375308659196079*I
sage: real(CDF(a))
1.1503557032549028

So that you can do:

sage: implicit_plot(lambda x,y:real_part(CDF(g(x+y*I))),(-3,3),(-3,3))
edit flag offensive delete link more

Comments

That's it! Many thanks for your help, tmonteil. I am really impressed by the speed of response and the expertise on this forum :-)

RuudH gravatar imageRuudH ( 2018-02-09 10:54:15 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-02-09 09:20:43 -0500

Seen: 52 times

Last updated: Feb 09