Ask Your Question
1

Create multivariate function of a list of variables

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

MLainz gravatar image

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

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
3

answered 2018-02-19 22:37:44 +0100

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

2 followers

Stats

Asked: 2018-02-19 19:45:29 +0100

Seen: 794 times

Last updated: Feb 20 '18