Ask Your Question

(f(g(x)) in Sage? How?

asked 2019-07-13 02:55:35 -0500

Hi everybody ! I am a total beginner and want to learn to use Sagemath. How do I write a script that calculates the following (f(g(x)). I thank you in advance for helping me. Ulf

edit retag flag offensive close merge delete



You can write f(g(x)) in Sage. In your situation: what is f? what is g?

vdelecroix gravatar imagevdelecroix ( 2019-07-14 03:48:47 -0500 )edit

Thanks! How do I define f(x) and g(x). I guess you have to tell SAGE what these functions are first?

jamt1961 gravatar imagejamt1961 ( 2019-07-16 02:26:34 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-07-15 16:12:10 -0500

dan_fulea gravatar image

You may use compose as in the following sample:

sage: h = compose(sin, cos)

sage: h(1.23456)

sage: sin(cos(1.23456))

sage: plot( compose(sin, cos), (0, pi) )
Launched png viewer for Graphics object consisting of 1 graphics primitive

(The explicit composition works, of course, but sometimes one needs the composition without passing through the explicit evaluation, as in the above plot example.)

See also:

edit flag offensive delete link more


Thanks! So I just write h = compose(x^2,x^3) and then I can put in values?

jamt1961 gravatar imagejamt1961 ( 2019-07-16 02:29:31 -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: 2019-07-13 02:55:35 -0500

Seen: 69 times

Last updated: Jul 15