bug in plot? Global constants seen as variables.

13 views
Skip to first unread message

Stan Schymanski

unread,
Feb 9, 2009, 5:35:35 AM2/9/09
to sage-support
Dear all,

For some reason, the meaning of the global constants pi and e (and
maybe others) becomes unavailable to the plot command in the following
example. Is this a bug?

----------------------------------------------------------------------
| Sage Version 3.2, Release Date: 2008-11-20 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------

sage: var('h delta phi doy t')
(h, delta, phi, doy, t)
sage: h = 1/12*pi*(t-12)
sage: delta = -23.45*pi/180*cos(2*pi*(doy+10)/365)
sage: sinbeta = cos(h)*cos(delta)*cos(phi)+sin(delta)*sin(phi)
sage: daylength = 12+24/180*arcsin(tan(phi)*sin(delta)/cos(delta))*180/
pi
sage: plot(pi*x,x,0,1)

sage: plot(exp(x),x,0,1)

sage: doy = 180
sage: phi = (30*pi/180).n()
sage: length = daylength.subs(locals()).n()
sage: t0 = 12-0.5*length
sage: t1 = 12+0.5*length
sage: plot(pi*x,x,0,1)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (546, 0))
[...]
ValueError: free variable: pi

sage: plot(exp(x),x,0,1)
[...]
ValueError: free variable: e


Funnily enough, the following fixes the pi-problem for the time being:

sage: pi=pi.n()

But e=e.n() does not fix the e-problem.

Can anyone help?

Thanks a lot,
Stan

Marshall Hampton

unread,
Feb 9, 2009, 2:34:44 PM2/9/09
to sage-support
I would guess the problem stems from the

sage: length = daylength.subs(locals()).n()

line somehow. I would recommend making daylength a function, instead
of substituting.

I am still not sure exactly what the problem is in the original code
though.

Stan Schymanski

unread,
Feb 10, 2009, 6:47:02 AM2/10/09
to sage-support
Dear Marshall,

Thanks a lot for your help. This should work in this case, but I don't
think I could get around using substitutions altogether (see, for
example, this thread:
http://groups.google.com/group/sage-support/browse_thread/thread/e62a83a6ac3c5d1d/e6e535972106bb15?lnk=gst&q=python+stan#e6e535972106bb15).
Should this be filed as a bug in subs?

Cheers
Stan
Reply all
Reply to author
Forward
0 new messages