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

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=sage ^--- 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 close merge delete

Sort by » oldest newest most voted

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))

more

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