Ask Your Question

Composite function

asked 2011-04-09 12:32:57 -0500

BobB gravatar image

updated 2011-04-09 12:35:42 -0500

If I define:


g(t) = (t, t^2, t^3)

f(x,y,z) = (2x,y+x+z,yx)

Is there a way for me to define the composite f(g(t)) without going through:


or something equally ugly?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2011-04-09 13:02:15 -0500

benjaminfjones gravatar image

If you let g be a tuple of expressions involving t you can use the Python * operator to use the tuple entries as your inputs x, y, and z:

sage: g = (t, t^2, t^3)
sage: f = lambda x,y,z: (2*x, y+x+z, y*x)
sage: f(*g)
(2*t, t^3 + t^2 + t, t^3)

If you want to define both g and f as lambda functions you could do:

sage: g = lambda t: (t, t^2, t^3)
sage: f = lambda x,y,z: (2*x, y+x+z, y*x)
sage: f(*g(t))
(2*t, t^3 + t^2 + t, t^3)
edit flag offensive delete link more


You don't need f to be a lambda function for this; using "f(x,y,z) = (2*x,y+x+z,y*x)" works just fine.

John Palmieri gravatar imageJohn Palmieri ( 2011-04-09 13:07:54 -0500 )edit

Thank you for the alternative. For the moment it looks like non-lambda functions work well. I'm not well versed in python and I'd like to make things look as much like mathematical notation as possible. Also, it seems using other properties (methods, functions?) like jacobian and derivative is more straight forward if lambda functions are avoided.

BobB gravatar imageBobB ( 2011-04-09 22:05:12 -0500 )edit

answered 2011-04-09 13:00:05 -0500

Ben Reynwar gravatar image

h(t) = f(*g(t))

edit flag offensive delete link more


Great! And very quick, thank you. I suppose I would have known that if I knew something about python? Or is * a sage operator of some sort?

BobB gravatar imageBobB ( 2011-04-09 13:08:29 -0500 )edit

It's a python thing -- see benjaminfjones' answer.

John Palmieri gravatar imageJohn Palmieri ( 2011-04-09 13:09:22 -0500 )edit

But it might be nice to have this work without that. See; if someone can come up with a better title for that ticket, be my guest.

kcrisman gravatar imagekcrisman ( 2011-04-11 17:07:50 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2011-04-09 12:32:57 -0500

Seen: 817 times

Last updated: Apr 09 '11