Ask Your Question

Create multivariate function of a list of variables

asked 2018-02-19 12:45:29 -0600

MLainz gravatar image

updated 2018-02-20 12:52:06 -0600

I have created a list of variables, myvars

I'd like to create a function of those variables, but

myvars = var('x y z')
 f = function('f')(myvars)

doesn't work.

Of course in my actual code I'm creating myvars programatically, so doing

 f = unction('f')(myvars[0], myvars[1], myvars[2])

is not convenient

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-02-19 15:37:44 -0600

eric_g gravatar image

You should use the star operator to unpack the tuple myvars, i.e. write the function argument as *myvars:

sage: myvars = var('x y z')
sage: f = function('f')(*myvars)
sage: f
f(x, y, z)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-02-19 12:45:29 -0600

Seen: 133 times

Last updated: Feb 20 '18