Ask Your Question
1

How to use matrices with @interact

asked 9 years ago

Julien gravatar image

updated 9 years ago

I found the following example here.

@interact
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?

Preview: (hide)

Comments

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

kcrisman gravatar imagekcrisman ( 9 years ago )

2 Answers

Sort by » oldest newest most voted
2

answered 9 years ago

kcrisman gravatar image

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

@interact
def _(m = input_grid(2,2, default = [[1,7],[3,4]], label='M=', to_value=matrix)):
    print m
    print m.eigenvalues()
Preview: (hide)
link

Comments

thanks a lot.

Julien gravatar imageJulien ( 9 years ago )

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 ( 9 years ago )
3

answered 9 years ago

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:

@interact
def _(m=input_box(list(identity_matrix(2)),type=matrix)):
    print type(m)
    print m
    print m.eigenvalues()
Preview: (hide)
link

Comments

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

Julien gravatar imageJulien ( 9 years ago )

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 http://doc.sagemath.org/html/en/refer... is supposed to work.

kcrisman gravatar imagekcrisman ( 9 years ago )

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 ( 9 years ago )

See my answer.

kcrisman gravatar imagekcrisman ( 9 years ago )

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: 9 years ago

Seen: 796 times

Last updated: Oct 21 '15