Ask Your Question

Create multivariate function of a list of variables

asked 2018-02-19 19:45:29 +0200

MLainz gravatar image

updated 2018-02-20 19:52:06 +0200

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 22:37:44 +0200

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 19:45:29 +0200

Seen: 572 times

Last updated: Feb 20 '18