Ask Your Question
1

How to use matrices with @interact

asked 2015-10-20 22:50:23 +0200

Julien gravatar image

updated 2015-10-20 23:01:57 +0200

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?

edit retag flag offensive close merge delete

Comments

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

kcrisman gravatar imagekcrisman ( 2015-10-21 01:25:15 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2015-10-21 23:14:19 +0200

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()
edit flag offensive delete link more

Comments

thanks a lot.

Julien gravatar imageJulien ( 2015-10-22 02:24:13 +0200 )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-22 04:48:32 +0200 )edit
3

answered 2015-10-20 23:24:23 +0200

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()
edit flag offensive delete link more

Comments

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

Julien gravatar imageJulien ( 2015-10-21 01:18:34 +0200 )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 http://doc.sagemath.org/html/en/refer... is supposed to work.

kcrisman gravatar imagekcrisman ( 2015-10-21 01:26:10 +0200 )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-21 02:00:58 +0200 )edit

See my answer.

kcrisman gravatar imagekcrisman ( 2015-10-21 23:14:32 +0200 )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

Stats

Asked: 2015-10-20 22:50:23 +0200

Seen: 636 times

Last updated: Oct 21 '15