Ask Your Question
0

Different errors

asked 2011-01-27 21:26:36 -0600

manifold gravatar image

Hi, im new to sage, but i like it. (i Have some expertise with mathematica, but not with sage).

I created a notebook on the uw.sagenb.org server. It contains the text: http://typewith.me/jmSO3JENxg

Sometimes a I get the error: Traceback (click to the left of this block for traceback) ... TypeError: 'sage.symbolic.expression.Expression' object is not iterable

Full error here: http://rn0.ru/show/1422/

If I want to use latex, in the second lowest field, i get an error: sh: dvipng: not found Full error here: http://rn0.ru/show/1421/

Somehow, the fields work sometimes, and sometimes they dont... I have the feeling I would need to "quit the kernel" like in mathematica, from time to time...

Does anyone know the errors?

edit retag flag offensive close merge delete

5 answers

Sort by ยป oldest newest most voted
2

answered 2011-01-28 00:13:12 -0600

DSM gravatar image

updated 2011-01-28 00:30:04 -0600

I couldn't reproduce the dvipng error, but I can explain the "TypeError: 'sage.symbolic.expression.Expression' object is not iterable" problem.

There are several different functions called "plot", including both the Sage one (which knows about and likes Sage expressions), and the plot in the matplotlib package you import in later cells with

from pylab import *

and

from matplotlib.pyplot import figure, axes, plot, xlabel, ylabel, title, \
     grid, savefig, show

This plot function doesn't know about Sage functions and expects an argument that it can loop over, which is exactly what the error message is trying to say: it's expecting something it can iterate over (like a list of points), but the sage expression you pass isn't.

The "sometimes it works, sometimes it doesn't" effect is simply measuring whether or not you executed a reset() in some cell, setting plot back to the Sage one, after you executed the above import, which is why it appears so random-- apparently your cell execution order habits are kind of random. :^)

Keeping the matplotlib functions in their own space by using the "import matplotlib.pyplot as plt"/"plt.plot" approach -- which you do in one cell -- and avoiding either "from pylab import *" or "from matplotlib.pyplot import plot" is a better idea if you're going to want to mix Sage plots and matplotlib plots.

edit flag offensive delete link more
0

answered 2011-01-28 01:04:32 -0600

manifold gravatar image

Thanks. That helps!

I think that solve all errors...

edit flag offensive delete link more
0

answered 2011-01-28 01:22:13 -0600

manifold gravatar image

hi... I just can't get rid of this error:

TypeError: 'sage.symbolic.expression.Expression' object is not iterable

I get it with this code: http://rn0.ru/show/1428/

(I have restarted the notebook)

And x is defined by. x = np.arange(0, 5, 0.1)

x is "iterable".. or not?

edit flag offensive delete link more
1

answered 2011-01-28 02:07:16 -0600

DSM gravatar image

Yep, x is iterable, as are the other arguments-- but that's not actually what the problem is. In this case the error message is a little deceptive, as it's actually what's inside y which is causing trouble. Let's look at the types involved:

sage: import numpy as np
sage: 
sage: x = np.arange(0, 5, 0.1)
sage: y = [e^(-i)+(random()-1/2)/10 for i in x]  
sage: ex = [random()/10 for i in y] 
sage: ey = [random()/10 for i in y] 
sage: for v in x,y,ex,ey:
....:     print len(v), type(v), type(v[0])
....:     
50 <type 'numpy.ndarray'> <type 'numpy.float64'>
50 <type 'list'> <type 'sage.symbolic.expression.Expression'>
50 <type 'list'> <type 'float'>
50 <type 'list'> <type 'float'>

And you see that the components of y aren't Python floats ('float') or numpy floats ('float64') [the difference between these two doesn't matter here] but Sage symbolic expressions, which (once again) matplotlib doesn't know what to do with.

Here the problem is caused by e:

sage: e
e
sage: type(e)
<type 'sage.symbolic.constants_c.E'>
sage: type(e^(-i))
<type 'sage.symbolic.expression.Expression'>

There are many ways around this problem: simply cast the array to floats, use "np.e", float(e), or (if you don't care about "symbolic" e) simply replace e, etc. The Sage plot functions automatically coerce to numerical values, as they should, but the matplotlib functions (possibly for speed reasons) don't do such a coercion.

edit flag offensive delete link more
0

answered 2011-01-28 02:14:08 -0600

manifold gravatar image

YESS... it works.. thousand thanks!!!

edit flag offensive delete link more

Comments

Glad I could help. Since Sage involves a lot of different packages, sometimes it's hard to get them all talking to each other the way you might think they should. But instead of a thousand thanks, I'll settle for you clicking on the checkmark and accepting my answer. :^)

DSM gravatar imageDSM ( 2011-01-28 02:25:15 -0600 )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

Stats

Asked: 2011-01-27 21:26:36 -0600

Seen: 1,000 times

Last updated: Jan 28 '11