First time here? Check out the FAQ!

Ask Your Question
1

Create multivariate function of a list of variables

asked 7 years ago

MLainz gravatar image

updated 7 years ago

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 7 years ago

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)
Preview: (hide)
link

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: 7 years ago

Seen: 922 times

Last updated: Feb 20 '18