Ask Your Question
0

unable to use interact

asked 2010-08-23 17:12:50 +0100

yotama9 gravatar image

Hi guys.

I'm tying to use interact to show a plot. I input the following commands:

@interact
def _(a=(0,2)):
    show(plot(sin(x*(1+a*x)), (x,0,6)), figsize=4)

which I found typing help(sage) and got an error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_171.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8
-*-\\n" +
_support_.preparse_worksheet_cell(base64.b64decode("X2ludGVyYWN0Xy5yZWNv\
bXB1dGUoIjc1Iik="),globals())+"\\n");
execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single')
  File "", line 1, in <module>

  File "/tmp/tmpgG2nqV/___code___.py", line 2, in <module>
    exec compile(u'_interact_.recompute("75")' + '\n', '', 'single')
  File "", line 1, in <module>

  File
"/home/yotam/Documents/Apps/sage/sage-4.5.2-linux-32bit-ubuntu_10.04_lts\
-i686-Linux/local/lib/python2.6/site-packages/sagenb-0.8.2-py2.6.egg/sag\
enb/notebook/interact.py", line 3746, in recompute
    S['function']()
  File
"/home/yotam/Documents/Apps/sage/sage-4.5.2-linux-32bit-ubuntu_10.04_lts\
-i686-Linux/local/lib/python2.6/site-packages/sagenb-0.8.2-py2.6.egg/sag\
enb/notebook/interact.py", line 2558, in _
    z = f(*[variables[arg] for arg in args])
  File "/tmp/tmpE4fUak/___code___.py", line 5, in _
    show(plot(sin(x*(_sage_const_1 +a*x)), (x,_sage_const_0
,_sage_const_6 )), figsize=_sage_const_4 )
TypeError: can't multiply sequence by non-int of type 'float'

What have I missed?

edit retag flag offensive close merge delete

Comments

You are probably right. I'll check this out later. Thanks

yotama9 gravatar imageyotama9 ( 2010-08-23 18:33:14 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2010-08-23 18:07:25 +0100

Hello yotama9,

I copied your code as-is into a new Sage Notebook and received no error. I have some guesses, though, as to what might be wrong.

  • _(Not as likely.)_ You have an extra comma somewhere where it shouldn't.
  • _(More likely.)_ You defined x as a list / tuple / Sequence somewhere previously. I tried the following and got a similar error:

(In Notebook:)

sage: x = [1,2]
sage: @interact
sage: def _(a=(0,2)):
         show(plot(sin(x*(1+a*x)), (x,0,6)), figsize=4)

Traceback (most recent call last):
...
TypeError: can't multiply sequence by non-int of type 'float'

That last line in the error text says that you're trying to multiply a list by a number. One way to fix this is to include the line statement x = var('x') just before the show(plot(...)) statement. That way x will locally (within the interact function) be a variable yet outside it will continue to be your list.

edit flag offensive delete link more

Comments

I think this is spot on, because if you just try `4.*x` you get a different error about MPFR numbers, while since `plot` makes floats you get this error with `float(4)*x` (same `x` as in your example).

kcrisman gravatar imagekcrisman ( 2010-08-24 09:47:29 +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

Stats

Asked: 2010-08-23 17:12:50 +0100

Seen: 617 times

Last updated: Aug 23 '10