Ask Your Question
1

Create multivariate function of a list of variables

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

MLainz gravatar image

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

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 15:37:44 -0500

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 12:45:29 -0500

Seen: 45 times

Last updated: Feb 20