ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 29 Feb 2020 05:59:33 +0100How to compose two functionshttps://ask.sagemath.org/question/50113/how-to-compose-two-functions/Suppose I have a function f(x)=x^2+1
What is the command to compose it with itself twice or thrice?
I was using:
f= (x^2+1)
g= lambda t: (t^2+1)
f(*g)
or
sage: g = lambda t: (t^2+1)
sage: f = lambda x: (x^+1)
sage: f(*g(t))
or
sage: x = var('x')
sage: f=x^2+1
sage: compose(f, 3, x)
Nothing works! Also, I don't know how to use the Dynamical system code in this case here.
Also, it would be of great help if you can give me one example command for the composition of two different functions
e.g f(x)=x^2+1 and g(x)=x^3+2 if it is not obvious from the answer of the composition of the same function twice.Sat, 29 Feb 2020 04:21:11 +0100https://ask.sagemath.org/question/50113/how-to-compose-two-functions/Answer by dsejas for <p>Suppose I have a function f(x)=x^2+1</p>
<p>What is the command to compose it with itself twice or thrice?</p>
<p>I was using:</p>
<p>f= (x^2+1)</p>
<p>g= lambda t: (t^2+1)</p>
<p>f(*g)</p>
<p>or </p>
<p>sage: g = lambda t: (t^2+1)
sage: f = lambda x: (x^+1)
sage: f(*g(t))</p>
<p>or</p>
<p>sage: x = var('x')</p>
<p>sage: f=x^2+1</p>
<p>sage: compose(f, 3, x)</p>
<p>Nothing works! Also, I don't know how to use the Dynamical system code in this case here.</p>
<p>Also, it would be of great help if you can give me one example command for the composition of two different functions
e.g f(x)=x^2+1 and g(x)=x^3+2 if it is not obvious from the answer of the composition of the same function twice.</p>
https://ask.sagemath.org/question/50113/how-to-compose-two-functions/?answer=50116#post-id-50116Hello, @Arnab! I suppose the following is the answer you're looking for. First define $f$:
f(x) = x^2 + 1
Now compose simply by writing:
f2(x) = f(f(x))
f3(x) = f(f(f(x)))
As you might guess, $f2$ is the composition $f\circ f$ ($f$ with itself), while $f3$ is the composition $f\circ f\circ f$ (three times $f$).
The same mechanism works for different functions. Let's define
f(x) = x^2 + 1
g(t) = t^3
Then you can write
fg(t) = f(g(t))
gf(x) = g(f(x))
The first one will give you $t^6+1$, while the second will give you $(x^2+1)^3$.
I hope this helps!Sat, 29 Feb 2020 05:59:33 +0100https://ask.sagemath.org/question/50113/how-to-compose-two-functions/?answer=50116#post-id-50116