Ask Your Question
1

How introduce inputs in a @interact sage program

asked 2012-01-17 10:52:51 +0200

anonymous user

Anonymous

updated 2012-01-17 11:34:33 +0200

kcrisman gravatar image

Concretely, how tranlate the following MATLAB program to SAGE:

n=input('number of vertices n= ');
m=input('number of edges m= ');
disp('write weighted edges as [v1 v2 w12]');
for i=1:m
    E(i,:)=input(['arco ',num2str(i), '= ']);
end
disp(E)
edit retag flag offensive close merge delete

Comments

Can you say exactly what this program is doing? It looks like you might have two different questions - one about how to get Sage to do this graph theory thing (listing the vertices and weights of the weighted edges?), the other about how to turn that into an interact.

kcrisman gravatar imagekcrisman ( 2012-01-17 11:35:54 +0200 )edit

exactly, for introduce a concrete graph I need know the number of vertices, the number of arcs and use these inputs for introduce other inputs of second level

canisvetus gravatar imagecanisvetus ( 2012-01-17 11:48:54 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2012-01-17 15:19:03 +0200

Jason Grout gravatar image

updated 2012-05-24 11:58:07 +0200

I don't know of a way to do this with the current interact implementation in Sage. You can do it with the singlecell server (which just executes a single Sage command, but you can embed it in any webpage), and hopefully soon the new interact implementation in the singlecell server will make its way back into Sage.

For example, see this exampleon aleph.sagemath.org:

@interact
def f(numbers=(1,10,1)):
    @interact(controls=[('x%d'%i, (0,10)) for i in range(numbers)])
    def s(multiplier=2, **kwargs):
        expr = "%s*(%s)"%(multiplier, '+'.join(sorted(kwargs)))
        print "%s is %s"%(expr, sum(kwargs.values())*multiplier)

Of course, if you just want to get input from the user in the notebook, you can just ask them to define the variables.

edit flag offensive delete link more

Comments

So we'll finally have a resolution to "have interact controls depend on other controls"? Amazing!!!

kcrisman gravatar imagekcrisman ( 2012-01-17 17:33:09 +0200 )edit

See also (apparently) http://ask.sagemath.org/question/261 and Trac ticket 3836 (I think, internet is slow right now for me).

kcrisman gravatar imagekcrisman ( 2012-01-17 17:35:24 +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: 2012-01-17 10:52:51 +0200

Seen: 9,832 times

Last updated: May 24 '12