Ask Your Question

How to use matrices with @interact

asked 2015-10-20 15:50:23 -0500

Julien gravatar image

updated 2015-10-20 16:01:57 -0500

I found the following example here.

def _(m=('matrix', identity_matrix(2))):
    print m.eigenvalues()

Unlike the other examples I've tried, this one does not work when evaluated in SageMathCell. But it works well in a SageMathCloud Worksheet.

What am I supposed to do to produce such a matrix interact that works when I embed it in html pages?

edit retag flag offensive close merge delete


Note: it also works in the Sage notebook; this is somehow a relatively new bug in the cell server.

kcrisman gravatar imagekcrisman ( 2015-10-20 18:25:15 -0500 )edit

2 answers

Sort by » oldest newest most voted

answered 2015-10-21 16:14:19 -0500

kcrisman gravatar image

I just tried this more or less from the documentation and it worked on the cell server.

def _(m = input_grid(2,2, default = [[1,7],[3,4]], label='M=', to_value=matrix)):
    print m
    print m.eigenvalues()
edit flag offensive delete link more


thanks a lot.

Julien gravatar imageJulien ( 2015-10-21 19:24:13 -0500 )edit

No problem; hopefully this will be fixed on the cell server within a couple weeks and it won't be an issue but it's nice to have this in a few places anyway.

kcrisman gravatar imagekcrisman ( 2015-10-21 21:48:32 -0500 )edit

answered 2015-10-20 16:24:23 -0500

ndomes gravatar image

Converting matrix to list and converting this list back to matrix by setting type=matrix is not straightforward but it works in sage cell server:

def _(m=input_box(list(identity_matrix(2)),type=matrix)):
    print type(m)
    print m
    print m.eigenvalues()
edit flag offensive delete link more


It works, thanks. Do you know how to use input_grid in this context?

Julien gravatar imageJulien ( 2015-10-20 18:18:34 -0500 )edit

input_gridis the canonical thing; the shortcut "u = matrix - an input_grid with to_value set to matrix.parent() and default values given by the matrix" from is supposed to work.

kcrisman gravatar imagekcrisman ( 2015-10-20 18:26:10 -0500 )edit

thanks @kcrisman: if possible, I was hoping for a ready-made command because I have not been able to adapt the documentation I found (including the one you refer to) about input_grid to this context. I really tried before asking.

Julien gravatar imageJulien ( 2015-10-20 19:00:58 -0500 )edit

See my answer.

kcrisman gravatar imagekcrisman ( 2015-10-21 16:14:32 -0500 )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


Asked: 2015-10-20 15:50:23 -0500

Seen: 138 times

Last updated: Oct 21 '15