Ask Your Question
1

Using Sage plotting capability on data from PARI/GP

asked 2018-02-08 12:49:41 +0100

RuudH gravatar image

I am trying to plot data in Sage that is generated by a function in PARI/GP, however keep getting type errors.

I use this simple example to illustrate the point:

f=(gp("Z(s)=zeta(s)"))
f(2)

This gives the correct output 1.6449340668482264364724151666460251892 and appears to be a 'normal' floating point number that I can indeed multiply/add with.

However, when I try the following:

plot(f,(2,6))

It keeps coming back with

TypeError: Error executing code in GP

I have studied most of the (limited) info on the Pari/GP interface and did read that PARI/GP always returns a string. I therefore tried to convert the returned value into a float, int etc., however nothing works. I very likely do something wrong (or not allowed) and would be grateful for any advice on what could be the issue here (esp. since f(2) gives the correct numerical floating point result).

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-02-08 20:06:09 +0100

slelievre gravatar image

The workaround here is to use a lambda expression.

This is a very general trick for any plotting problem where there are problems with the function or expression.

Using the following should get you the plot you want.

sage: plot(lambda x: f(x), (2, 6))
edit flag offensive delete link more

Comments

Many thanks! This works very well indeed. I had seen the use of the lambda before, but never related it to calls with PARI/GP objects.

RuudH gravatar imageRuudH ( 2018-02-08 20:10:46 +0100 )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-08 12:49:41 +0100

Seen: 362 times

Last updated: Feb 08 '18